Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Fortran

Idiom #156 Format integer with zero-padding

Assign to the string s the value of the integer i in 3 decimal digits. Pad with zeros if i < 100. Keep all digits if i1000.

write (unit=s,fmt='(I0.3)') i

This assumes that s is long enough.
(def s (format "%03d" i))

New implementation...
< >
programming-idioms.org