ruby-1.8.7 > 1.55.round(1)
=> 1.6
ruby-1.8.7 > 1.555.round(2)
=> 1.56
ruby-1.8.7 > 1.155.round(2)
=> 1.16
ruby-1.8.7 > 10.156.round(2)
=> 10.16
ruby-1.8.7 > 10.155.round(2)
=> 10.15
ruby-1.8.7 > 10.165.round(2)
=> 10.16
What gives? Am I missing something?
EDIT
ruby-1.9.2 > 10.155.round(2)
=> 10.15
ruby-1.9.2 > 10.165.round(2)
=> 10.16
Floating point values are not precise. Your 10.165 is represented on paper/the screen as 10.165, but in memory it’s represented as something extremely close to 10.165… whether it rounds up or down is a matter of which direction the error happens to fall in.
If you need accurate handling of fractional numbers, you can either represent them as BigDecimal (with a decimal scale/precision notation), or as Rational (with a fractional numerator/denominator notation).