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.
Thats IEEE 754 float behaviour, yes. python behaves exactly the same.
- --
Florian Gilcher
smtp: flo@andersground.net
jabber: Skade@jabber.ccc.de
gpg: 533148E2
On Nov 29, 2009, at 12:06 AM, Ruby Newbee 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.
Florian Gilcher 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 Gilcher
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 Wilhelm <steve@studio831.com>:
Florian Gilcher wrote:
On Nov 29, 2009, at 12:06 AM, Ruby Newbee 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.
And PHP 5 as well.
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.
On Sun, Nov 29, 2009 at 3:34 AM, Ruby Newbee <rubynewbee@gmail.com> wrote:
Thanks all~
2009/11/29 Steve Wilhelm <steve@studio831.com>:
> Florian Gilcher wrote:
>
>> On Nov 29, 2009, at 12:06 AM, Ruby Newbee wrote:
>>
>>> 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.
>>
>>
>> Thats IEEE 754 float behaviour, yes. python behaves exactly the same.
>>>>
>
> And PHP 5 as well.
>
--
Horofox @ irc.freenode.net | #ruby, #ubuntu & #rails
Thiago Fernandes Massa
11 83979414
Thiago Massa 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.
Best,
--
Marnen Laibow-Koser
http://www.marnen.org
marnen@marnen.org
--
Posted via http://www.ruby-forum.com/\.