Logo

Programming-Idioms

History of Idiom 156 > diff from v3 to v4

Edit summary for version 4 by steenslag:
New Ruby implementation by user [steenslag]

Version 3

2017-03-19, 20:53:48

Version 4

2017-03-26, 16:40:55

Idiom #156 Format integer with zero-padding

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

Idiom #156 Format integer with zero-padding

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

Extra Keywords
pad leading fixed width
Extra Keywords
pad leading fixed width
Code
s = "%03d" % i