From: Caleb Clausen Date: 2010-07-13T23:49:43+09:00 Subject: Re: Ruby 1.9.2 float precision On 7/13/10, Diogo Almeida wrote: > Robert Klemme wrote: >> 2010/7/13 Diogo Almeida : >> >> I question the validity of the test. Expecting a particular >> formatting of a float number without giving a concrete format is at >> least fragile (as you have discovered) - I would even call it wrong. >> Different than for integers there is no common agreed way to convert >> floats to strings so if you want a particular formatting you need to >> make it part of the test. An alternative would be a regexp match >> against \A4\.6+7\z >> >> irb(main):001:0> /\A4\.6+7\z/ =~ (14.0/3).to_s >> => 0 > > Yes, I found it odd when I saw it myself. Though, since this was a > recent change I figured someone could know how to fallback to the "old > formatting", without having to use regex, or other alternative > approaches. 1.9.2 has been changed so that float.to_s.to_f always round-trips with a minimal string representation. This was not true in the past. This new behavior is better; there's no flag or anything to get the old behavior back. I suggest you follow Robert's suggestions for fixing the test.