Two different rounding methods of floats show different results.
"%.2f" % 0.015 # => "0.01"
0.015.round(2) # => 0.02
One is string and the other a float. When rounding anything but 0.5, it rounds correctly or rather the same way as the round function.
"%.2f" % 0.01500000000000001 # => "0.02"
Also, it doesn't always behave like that:
[0.005, 0.015, 0.025, 0.035, 0.045, 0.055, 0.065, 0.075, 0.085, 0.095].map { |x| "%.2f" % x}
# => ["0.01", "0.01", "0.03", "0.04", "0.04", "0.06", "0.07", "0.07", "0.09", "0.10"]
I am not sure if this is technically a bug, but at least it is very counter intuitive. Does anybody know why two rounding methods act that differently?