Formatted numeric output: Difference between revisions

Content deleted Content added
CalmoSoft (talk | contribs)
No edit summary
Edmund (talk | contribs)
Line 307: Line 307:
{{trans|java}} Using java format strings
{{trans|java}} Using java format strings
<lang lisp>(printf "%09.3f" 7.125) ; format works the same way (without side the effect of printing)</lang>
<lang lisp>(printf "%09.3f" 7.125) ; format works the same way (without side the effect of printing)</lang>

=={{header|COBOL}}==
This is actually the easiest kind of numeric output to achieve in COBOL, because it requires no adjustments from the way numbers are stored internally (in fixed-point decimal). Each variable declaration requires a <tt>PIC</tt> or <tt>PICTURE</tt> clause describing the kind of data that will be stored there. In this case, we have <tt>9</tt> (a decimal digit), repeated five times; then <tt>V</tt>, the decimal point (cf. French <i>virgule</i>); and then three more decimal digits. Other terms that can appear in <tt>PICTURE</tt> clauses include <tt>A</tt> (a letter of the alphabet), <tt>X</tt> (a character), and <tt>Z</tt> (a decimal digit to be printed with leading spaces instead of leading zeros).
<lang cobol>IDENTIFICATION DIVISION.
PROGRAM-ID. NUMERIC-OUTPUT-PROGRAM.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-EXAMPLE.
05 X PIC 9(5)V9(3).
PROCEDURE DIVISION.
MOVE 7.125 TO X.
DISPLAY X UPON CONSOLE.
STOP RUN.</lang>
{{out}}
<pre>00007.125</pre>


=={{header|Common Lisp}}==
=={{header|Common Lisp}}==