def print_float(value) sprintf('%05.2f', value) end print_float(1) # => "01.00" print_float(2.4) # => "02.40" print_float(1.4455) # => "01.45"