Logo

Programming-Idioms

History of Idiom 156 > diff from v23 to v24

Edit summary for version 24 by ddd:
[Java] ff

Version 23

2021-09-15, 10:44:58

Version 24

2021-09-15, 10:45:50

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.

Variables
s,i
Variables
s,i
Extra Keywords
pad leading fixed width
Extra Keywords
pad leading fixed width
Code
String s = String.format("W%03d", i);
Code
String s = String.format("W%03d%c", i);