Format descriptors in Fortran
The format string is a little language: i0, f9.2, and es for scientific.
program format_descriptors
implicit none
real :: price = 1234.5
integer :: stock = 87
! Edit descriptors: i0 bare integer, f fixed point, a text, x space.
print '(a, i0, a)', "on the shelf: ", stock, " tins"
print '(a, f9.2)', "invoice: ", price
! Repeat counts stamp columns; es gives scientific notation.
print '(3(i4))', 61, 68, 74
print '(a, es10.3)', "in shorthand: ", price
end program format_descriptors
How it works
'(a, i0, a)'prints text, a bare integer, text — no width guessing.f9.2fixes the decimal layout for money-like output.3(i4)repeats a column three times, andes10.3goes scientific.
Keywords and builtins used here
endimplicitintegernoneprintprogramreal
The run, in numbers
- Lines
- 12
- Characters to type
- 411
- Tokens
- 47
- Three-star pace
- 60 tpm
At the three-star pace of 60 tokens a minute, this run takes about 47 seconds.
Step 2 of 3 in Strings & formats, step 17 of 27 in Language basics.