Formatted numeric output: Difference between revisions

→‎On the other hand: Agh. Out by one in counting...
(→‎On the other hand: Agh. Out by one in counting...)
Line 647:
IV = V !Grab the integer part.
WRITE (6,1) V,IV
1 FORMAT (F8F9.3,T1,I4I5.45)
END
</lang>
Output is
000700007.125
This would need adjustment for other sizes, but works as follows: The value part is printed (in the format system's working area) as "bbb7bbbb7.125" (b's standing for spaces), then the T1 moves the finger back to column one, and the I4I5.45 writes out "000700007", the .45 addendeum to I4I5 meaning print leading zeroes rather than leading spaces. It does not overwrite the subsequent ".125", and as no further output items appear the deed is done. Only later Fortran offers the addendum feature, but the Tab feature is much older.
 
Another approach would be to write forth a literal "0000000" atinstead of the startinteger, but this is less flexible. In the absence of the .45 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|gnuplot}}==
1,220

edits