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

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.

import "fmt"
s := fmt.Sprintf("%03d", i)
import std.format : format;
string s = format("%03d", i);
1
s := format('%.3d',[i]);
s = "%03d" % i
let s = format!("{:03}", i);

Do you know the best way to do this in your language ?
New implementation...

Idiom created by

programming-idioms.org