Logo

Programming-Idioms

History of Idiom 156 > diff from v22 to v23

Edit summary for version 23 by ddd:
[Java] ddd

Version 22

2020-05-30, 00:33:48

Version 23

2021-09-15, 10:44:58

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("%03d", i);
Code
String s = String.format("W%03d", i);