irb(main):026:0> 10.499999999999999.round
=> 10
irb(main):027:0> 10.4999999999999999.round
=> 11
Does this happen due to the float problem in any languages including
ruby?
Thanks.
irb(main):026:0> 10.499999999999999.round
=> 10
irb(main):027:0> 10.4999999999999999.round
=> 11
Does this happen due to the float problem in any languages including
ruby?
Thanks.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Nov 29, 2009, at 12:06 AM, Ruby N. wrote:
irb(main):026:0> 10.499999999999999.round
=> 10
irb(main):027:0> 10.4999999999999999.round
=> 11Does this happen due to the float problem in any languages including
ruby?
Thanks.
Thats IEEE 754 float behaviour, yes. python behaves exactly the same.
Florian G.
smtp: [email protected]
jabber: [email protected]
gpg: 533148E2
-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.0.12 (Darwin)
iEYEARECAAYFAksR80wACgkQyLKU2FMxSOLkpwCdFwIj6FfsGK3+ZFFVLPQV0XwJ
Xa8AnAp6o5sxct7fsDrJUWUkIJ0QmB19
=bERM
-----END PGP SIGNATURE-----
Florian G. wrote:
On Nov 29, 2009, at 12:06 AM, Ruby N. wrote:
irb(main):026:0> 10.499999999999999.round
=> 10
irb(main):027:0> 10.4999999999999999.round
=> 11Does this happen due to the float problem in any languages including
ruby?
Thanks.Thats IEEE 754 float behaviour, yes. python behaves exactly the same.
Florian G.
And PHP 5 as well.
php -r ‘echo sprintf (“PHP Version = %s\nround(10.499999999999999) =
%d\nround(10.4999999999999999) = %d\n”, phpversion(),
round(10.499999999999999), round(10.4999999999999999));’
PHP Version = 5.2.6
round(10.499999999999999) = 10
round(10.4999999999999999) = 11
Thanks all~
2009/11/29 Steve W. [email protected]:
Does this happen due to the float problem in any languages including
ruby?
Thanks.Thats IEEE 754 float behaviour, yes. python behaves exactly the same.
In C i think its 14/15 significant digits and its probably why.
If you want that much precision, find a way to use a bigger float.
Thiago M. wrote:
In C i think its 14/15 significant digits and its probably why.
If you want that much precision, find a way to use a bigger float.
BigDecimal and Rational will do the trick.
Marnen Laibow-Koser
http://www.marnen.org
[email protected]
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs