Padding zeros in front of a number using String#rjust '12'.rjust(7,'0') #=> "0000012" Resources String[ruby-doc.org] Ruby: How to add zeros to front of a number string using sprintf()[stackoverflow.com]