From: Robert Klemme Date: 2010-09-21T15:30:16+09:00 Subject: Re: Is this a bug? On 21.09.2010 00:39, Gerry Jenkins wrote: > I did discover that there are various ways of rounding just before your > reply at http://en.wikipedia.org/wiki/Rounding > > I am writing a ruby web based unit testing for my java students to > submit their programs to. > > My real problem is that sprintf in ruby behaves differently in this > regard to how java rounds. Since you are coming from a Java background I guess you are aware that JUnit's TestCase uses a delta for equals comparisons of float and double: http://www.junit.org/junit/javadoc/3.8.1/junit/framework/Assert.html > Oh well, I fixed it by creating unit test data that was within the > precision of the final java output, so that rounding was not used in the > unit testing. The proper solution IMHO would be a comparison of numeric values (i.e. not of strings) that takes the delta into account much the same way as it's done in JUnit because there is also named mismatch between the binary internal representation and the decimal external representation that we humans love to use. Cheers robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/