Formatted numeric output: Difference between revisions

Rename Perl 6 -> Raku, alphabetize, minor clean-up
(add task to ARM64 assembly Raspberry Pi)
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
Line 28:
00007.125
</pre>
 
=={{header|AArch64 Assembly}}==
{{works with|as|Raspberry Pi 3B version Buster 64 bits}}
Line 237 ⟶ 238:
 
</lang>
 
=={{header|AutoHotkey}}==
contributed by Laszlo on the ahk [http://www.autohotkey.com/forum/post-276467.html#276467 forum]
<lang AutoHotkey>MsgBox % pad(7.25,7) ; 0007.25
MsgBox % pad(-7.25,7) ; -007.25
 
pad(x,len) { ; pad with 0's from left to len chars
IfLess x,0, Return "-" pad(SubStr(x,2),len-1)
VarSetCapacity(p,len,Asc("0"))
Return SubStr(p x,1-len)
}</lang>
 
=={{header|AWK}}==
Line 250 ⟶ 262:
 
Same output as the C code.
 
=={{header|AutoHotkey}}==
contributed by Laszlo on the ahk [http://www.autohotkey.com/forum/post-276467.html#276467 forum]
<lang AutoHotkey>MsgBox % pad(7.25,7) ; 0007.25
MsgBox % pad(-7.25,7) ; -007.25
 
pad(x,len) { ; pad with 0's from left to len chars
IfLess x,0, Return "-" pad(SubStr(x,2),len-1)
VarSetCapacity(p,len,Asc("0"))
Return SubStr(p x,1-len)
}</lang>
 
=={{header|BaCon}}==
Line 389 ⟶ 390:
Hexadecimal: 0000007.2
Binary: 00111.001</pre>
 
=={{header|C}}==
<lang c>#include <stdio.h>
main(){
float r=7.125;
printf(" %9.3f\n",-r);
printf(" %9.3f\n",r);
printf(" %-9.3f\n",r);
printf(" %09.3f\n",-r);
printf(" %09.3f\n",r);
printf(" %-09.3f\n",r);
return 0;
}</lang>
{{out}}
-7.125
7.125
7.125
-0007.125
00007.125
7.125
 
=={{header|C sharp|C#}}==
Line 413 ⟶ 434:
}
</lang>
 
=={{header|C}}==
<lang c>#include <stdio.h>
main(){
float r=7.125;
printf(" %9.3f\n",-r);
printf(" %9.3f\n",r);
printf(" %-9.3f\n",r);
printf(" %09.3f\n",-r);
printf(" %09.3f\n",r);
printf(" %-09.3f\n",r);
return 0;
}</lang>
{{out}}
-7.125
7.125
7.125
-0007.125
00007.125
7.125
 
=={{header|C++}}==
Line 851 ⟶ 852:
7.125
</pre>
 
=={{header|FreeBASIC}}==
<lang freebasic>' FB 1.05.0 Win64
 
#Include "vbcompat.bi"
 
Dim s As String = Format(7.125, "00000.0##")
Print s
Sleep</lang>
 
{{out}}
<pre>
00007.125
</pre>
 
=={{header|Free Pascal}}==
''See [[#Pascal|Pascal]]''
 
=={{header|F_Sharp|F#}}==
Line 891 ⟶ 875:
}
</lang>
 
=={{header|Fōrmulæ}}==
 
In [https://wiki.formulae.org/Formatted_numeric_output this] page you can see the solution of this task.
 
Fōrmulæ programs are not textual, visualization/edition of programs is done showing/manipulating structures but not text ([http://wiki.formulae.org/Editing_F%C5%8Drmul%C3%A6_expressions more info]). Moreover, there can be multiple visual representations of the same program. Even though it is possible to have textual representation &mdash;i.e. XML, JSON&mdash; they are intended for transportation effects more than visualization and edition.
 
The option to show Fōrmulæ programs and their results is showing images. Unfortunately images cannot be uploaded in Rosetta Code.
 
=={{header|Forth}}==
Line 959 ⟶ 935:
 
Another approach would be to write forth a literal "0000" instead of the integer, but this is less flexible. In the absence of the .5 addendum, write the output to a character string (or equivalent), replace leading spaces by zeroes (watching out for negative numbers), and print the result.
 
=={{header|Free Pascal}}==
''See [[#Pascal|Pascal]]''
 
=={{header|FreeBASIC}}==
<lang freebasic>' FB 1.05.0 Win64
 
#Include "vbcompat.bi"
 
Dim s As String = Format(7.125, "00000.0##")
Print s
Sleep</lang>
 
{{out}}
<pre>
00007.125
</pre>
 
=={{header|FutureBasic}}==
Line 970 ⟶ 963:
00007.125
</pre>
 
=={{header|Fōrmulæ}}==
 
In [https://wiki.formulae.org/Formatted_numeric_output this] page you can see the solution of this task.
 
Fōrmulæ programs are not textual, visualization/edition of programs is done showing/manipulating structures but not text ([http://wiki.formulae.org/Editing_F%C5%8Drmul%C3%A6_expressions more info]). Moreover, there can be multiple visual representations of the same program. Even though it is possible to have textual representation &mdash;i.e. XML, JSON&mdash; they are intended for transportation effects more than visualization and edition.
 
The option to show Fōrmulæ programs and their results is showing images. Unfortunately images cannot be uploaded in Rosetta Code.
 
=={{header|Gambas}}==
Line 1,039 ⟶ 1,040:
}
</lang>
 
=={{header|IDL}}==
[[Category:IDL]]
 
<lang idl>n = 7.125
print, n, format='(f08.3)'
;==> 0007.125</lang>
 
=={{header|Icon}} and {{header|Unicon}}==
Line 1,069 ⟶ 1,063:
 
{{libheader|Icon Programming Library}} provides [http://www.cs.arizona.edu/icon/library/src/procs/printf.icn printf]
 
=={{header|IDL}}==
[[Category:IDL]]
 
<lang idl>n = 7.125
print, n, format='(f08.3)'
;==> 0007.125</lang>
 
=={{header|IS-BASIC}}==
Line 1,295 ⟶ 1,296:
print(string.format("%09.3d",7.125))
</lang>
 
=={{header|M2000 Interpreter}}==
We can use ? as Print
Line 1,473 ⟶ 1,475:
{{works with|Perl|5.x}}
<lang perl>printf "%09.3f\n", 7.125;</lang>
 
=={{header|Perl 6}}==
<lang perl6>say 7.125.fmt('%09.3f');</lang>
 
=={{header|Phix}}==
Line 1,665 ⟶ 1,664:
00007.125
</lang>
 
=={{header|Raku}}==
(formerly Perl 6)
<lang perl6>say 7.125.fmt('%09.3f');</lang>
 
=={{header|Raven}}==
<lang raven>7.125 "%09.3f" print
 
00007.125</lang>
{{trans|Python}}
<lang raven>define PI
-1 acos
PI exp PI - as r
r print "\n" print
r "" prefer "s=%s!\n" print
r dup dup dup dup "e=%e f=%f g=%g G=%G!\n" print
-1 r * dup dup "e=%9.4e f=%9.4f g=%9.4g!\n" print
r dup dup "e=%9.4e f=%9.4f g=%9.4g!\n" print
r dup dup "e=%-9.4e f=%-9.4f g=%-9.4g!\n" print
r -1 * dup dup "e=%09.4e f=%09.4f g=%09.4g!\n" print
r dup dup "e=%09.4e f=%09.4f g=%09.4g!\n" print
r dup dup "e=%-09.4e f=%-09.4f g=%-09.4g!\n" print</lang>
<lang raven>19.9991
s=19.999100!
e=1.999910e+01 f=19.999100 g=19.9991 G=19.9991!
e=-1.9999e+01 f= -19.9991 g= -20!
e=1.9999e+01 f= 19.9991 g= 20!
e=1.9999e+01 f=19.9991 g=20 !
e=-1.9999e+01 f=-019.9991 g=-00000020!
e=1.9999e+01 f=0019.9991 g=000000020!
e=1.9999e+01 f=19.9991 g=20 !</lang>
 
=={{header|REBOL}}==
Line 1,711 ⟶ 1,742:
00007.125
7.125</pre>
 
=={{header|Raven}}==
<lang raven>7.125 "%09.3f" print
 
00007.125</lang>
{{trans|Python}}
<lang raven>define PI
-1 acos
PI exp PI - as r
r print "\n" print
r "" prefer "s=%s!\n" print
r dup dup dup dup "e=%e f=%f g=%g G=%G!\n" print
-1 r * dup dup "e=%9.4e f=%9.4f g=%9.4g!\n" print
r dup dup "e=%9.4e f=%9.4f g=%9.4g!\n" print
r dup dup "e=%-9.4e f=%-9.4f g=%-9.4g!\n" print
r -1 * dup dup "e=%09.4e f=%09.4f g=%09.4g!\n" print
r dup dup "e=%09.4e f=%09.4f g=%09.4g!\n" print
r dup dup "e=%-09.4e f=%-09.4f g=%-09.4g!\n" print</lang>
<lang raven>19.9991
s=19.999100!
e=1.999910e+01 f=19.999100 g=19.9991 G=19.9991!
e=-1.9999e+01 f= -19.9991 g= -20!
e=1.9999e+01 f= 19.9991 g= 20!
e=1.9999e+01 f=19.9991 g=20 !
e=-1.9999e+01 f=-019.9991 g=-00000020!
e=1.9999e+01 f=0019.9991 g=000000020!
e=1.9999e+01 f=19.9991 g=20 !</lang>
 
=={{header|REXX}}==
10,327

edits