Formatted numeric output: Difference between revisions

Content added Content deleted
(add task to ARM64 assembly Raspberry Pi)
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
Line 28: Line 28:
00007.125
00007.125
</pre>
</pre>

=={{header|AArch64 Assembly}}==
=={{header|AArch64 Assembly}}==
{{works with|as|Raspberry Pi 3B version Buster 64 bits}}
{{works with|as|Raspberry Pi 3B version Buster 64 bits}}
Line 237: Line 238:


</lang>
</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}}==
=={{header|AWK}}==
Line 250: Line 262:


Same output as the C code.
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}}==
=={{header|BaCon}}==
Line 389: Line 390:
Hexadecimal: 0000007.2
Hexadecimal: 0000007.2
Binary: 00111.001</pre>
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#}}==
=={{header|C sharp|C#}}==
Line 413: Line 434:
}
}
</lang>
</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++}}==
=={{header|C++}}==
Line 851: Line 852:
7.125
7.125
</pre>
</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#}}==
=={{header|F_Sharp|F#}}==
Line 891: Line 875:
}
}
</lang>
</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}}==
=={{header|Forth}}==
Line 959: Line 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.
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}}==
=={{header|FutureBasic}}==
Line 970: Line 963:
00007.125
00007.125
</pre>
</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}}==
=={{header|Gambas}}==
Line 1,039: Line 1,040:
}
}
</lang>
</lang>

=={{header|IDL}}==
[[Category:IDL]]

<lang idl>n = 7.125
print, n, format='(f08.3)'
;==> 0007.125</lang>


=={{header|Icon}} and {{header|Unicon}}==
=={{header|Icon}} and {{header|Unicon}}==
Line 1,069: Line 1,063:


{{libheader|Icon Programming Library}} provides [http://www.cs.arizona.edu/icon/library/src/procs/printf.icn printf]
{{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}}==
=={{header|IS-BASIC}}==
Line 1,295: Line 1,296:
print(string.format("%09.3d",7.125))
print(string.format("%09.3d",7.125))
</lang>
</lang>

=={{header|M2000 Interpreter}}==
=={{header|M2000 Interpreter}}==
We can use ? as Print
We can use ? as Print
Line 1,473: Line 1,475:
{{works with|Perl|5.x}}
{{works with|Perl|5.x}}
<lang perl>printf "%09.3f\n", 7.125;</lang>
<lang perl>printf "%09.3f\n", 7.125;</lang>

=={{header|Perl 6}}==
<lang perl6>say 7.125.fmt('%09.3f');</lang>


=={{header|Phix}}==
=={{header|Phix}}==
Line 1,665: Line 1,664:
00007.125
00007.125
</lang>
</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}}==
=={{header|REBOL}}==
Line 1,711: Line 1,742:
00007.125
00007.125
7.125</pre>
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}}==
=={{header|REXX}}==