Logo

Programming-Idioms

History of Idiom 156 > diff from v4 to v5

Edit summary for version 5 by TheVTM:
New Rust implementation by user [TheVTM]

Version 4

2017-03-26, 16:40:55

Version 5

2017-04-27, 10:38:26

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
let s = format!("{:03}", i);
Doc URL
https://doc.rust-lang.org/std/fmt/
Demo URL
https://is.gd/XmMNIm