From: Robert Klemme Date: 2007-03-20T06:40:12+09:00 Subject: Re: truncate trouble On 19.03.2007 20:37, Greg Lorriman wrote: > This > > ('40.12'.to_f*100).to_i > > results in this integer : > > 4011 > > This is a bit of surprise. I'm using 1.8.4 on windows. Is this a bug? > Is there another floating type that avoids this problem? I;m not > seeing anything in the docs that might have warned me. No, that's a normal rounding error that comes with floats: irb(main):001:0> f='40.12'.to_f => 40.12 irb(main):002:0> "%20.10f" % f => " 40.1200000000" irb(main):003:0> "%40.30f" % f => " 40.119999999999997442046151263639" irb(main):004:0> "%40.30f" % (f*100) => " 4011.999999999999545252649113535881" If you look at the last line it becomes clear why you get 4011 as result. Kind regards robert