From: Glenn Jackman Date: 2009-07-23T03:17:19+09:00 Subject: Re: Bug Rounding Floats? (9.245 * 100).round => 924? S/B 925! At 2009-07-22 02:08PM, "Glenn Jackman" wrote: > At 2009-07-22 01:37PM, "Thomas Preymesser" wrote: > > [Note: parts of this message were removed to make it a legal post.] > > > > 2009/7/22 ddoherty03 > > > > > > > For example, (9.245 * 100).round should be 925, but my ruby gives 924. > > > > > > > try what your term really is: > > > > printf("%.50f",9.245 * 100) > > Welcome to IEEE floating-point arithmetic. Any programming language > that uses it will be subject to the same results. A workaround, convert the expression to a string and back to a number: num = Float("%.1f" % (9.245 * 100)).round puts "yippee" if num == 925 -- Glenn Jackman Write a wise saying and your name will live forever. -- Anonymous