David - Musings of an SRE

Add leading zeroes in Ruby

To add leading zeroes infront of a number in ruby, try this:

# with 5 being the number you want to have the leading zeroes added to
irb> "%03d" % 5
=> 005 # 3 leading 0 digits with number 5 .

Source:

How can I output leading zeroes in ruby - Stackoverflow