From: Benoit Daloze Date: 2010-01-16T07:01:30+09:00 Subject: [ruby-core:27602] Re: [Bug #2608] 1999.0 becomes 1998 --0016e65aee2a036419047d3b1d06 Content-Type: text/plain; charset=ISO-8859-1 Welcome to the world of Float ;) (look the mailing list about Float, we will not repeat the same 100 times ;) ) ~ $> ruby -ve 'p 19.99 * 100' ruby 1.9.2dev (2010-01-14 trunk 26319) [x86_64-darwin10.2.0] 1998.9999999999998 In 1.9, you would be able to see the Float with all the decimals, with no rounding like before. (For once I admit this new view is quite useful, but I would do this behavior only for #inspect, not #to_s) Never expect Float to be exact, consider them as approximation. 2010/1/15 Edmond Chui > Bug #2608: 1999.0 becomes 1998 > http://redmine.ruby-lang.org/issues/show/2608 > > Author: Edmond Chui > Status: Open, Priority: High > ruby -v: 1.8.7 > > The following script generate wrong result > > a = 19.99 * 100 > puts a.to_i # Prints out 1998. Should be 1999. > > > ---------------------------------------- > http://redmine.ruby-lang.org > > --0016e65aee2a036419047d3b1d06 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Welcome to the world of Float ;)
(look the mailing list about Float, we = will not repeat the same 100 times ;) )

~ $> ruby -ve 'p 19.9= 9 * 100'
ruby 1.9.2dev (2010-01-14 trunk 26319) [x86_64-darwin10.2.0= ]
1998.9999999999998

In 1.9, you would be able to see the Float with a= ll the decimals, with no rounding like before.
(For once I admit this ne= w view is quite useful, but I would do this behavior only for #inspect, not= #to_s)

Never expect Float to be exact, consider them as approximation.

=
2010/1/15 Edmond Chui <= redmine@ruby-lang.org>
Bug #2608: 1999.0= becomes 1998
http://redmine.ruby-lang.org/issues/show/2608

Author: Edmond Chui
Status: Open, Priority: High
ruby -v: 1.8.7

The following script generate wrong result

a =3D 19.99 * 100
puts a.to_i =A0# Prints out 1998. Should be 1999.


----------------------------------------
http://redmine.r= uby-lang.org


--0016e65aee2a036419047d3b1d06--