From: Ted Flethuseo Date: 2011-03-04T07:27:49+09:00 Subject: Re: float precision Robert Klemme wrote in post #727777: > 2008/9/13 thomas peklak : >> You are right, multiplying with 0.01 is even fast, see the benchmarks: >> >> require 'benchmark' >> user system total real >> SPf : 5.590000 0.050000 5.640000 ( 5.720373) >> *100 : 3.760000 0.040000 3.800000 ( 3.829771) >> *.01 : 1.770000 0.010000 1.780000 ( 1.811917) > > It's even more efficient to calculate with the full precision and > round only on output. :-) > > Cheers > > robert This doesn't seem to work for certain numbers though... is there a way to round this 7.17... e+25: puts "#{cd}\t#{(100 * thr.max).round*0.01}" output .. 1000 7.17897987691824e+25 200 3.35 4000 0.99 20000 0.69 -- Posted via http://www.ruby-forum.com/.