From: "trans. (T. Onoma)" Date: 2004-10-15T23:28:13+09:00 Subject: Re: Rounding to X digits On Thursday 14 October 2004 01:55 pm, Markus wrote: | Here's mine (with a few extras): | | class Numeric | def iff(cond) | cond ? self : self-self | end | def to_the_nearest(n) | n*(self/n).round | end | def aprox(x,n=0.001) | (to_the_nearest n) == (x.to_the_nearest n) | end | def at_least(x); (self >= x) ? self : x; end | def at_most(x); (self <= x) ? self : x; end | end | | def to_the_nearest(n) | n*(self/n).round | end def round_to_nearest( n=0.01 )    (self * (1/n)).round.to_f / (1/n)   end For some reason they don't give the exact same answer. Try an edge case. irb(main):066:0> 0.1 * (134.45/0.1).round => 134.4 irb(main):067:0> (134.45 * (1/0.1)).round.to_f / (1/0.1) => 134.5 T.