Logo

Programming-Idioms

History of Idiom 156 > diff from v20 to v21

Edit summary for version 21 by programming-idioms.org:
New JS implementation by user [programming-idioms.org]

Version 20

2020-05-03, 20:32:13

Version 21

2020-05-30, 00:33:20

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
let s = i.toString();
if(i<100)
	s = ('00'+i).slice(-3);