Hi,
I found a weird problem.
In ruby 1.8.5, I get the following result in irb.
BigDecimal.new("86.02").to_f #=> 86.2
I don't know if this is a ruby bug or machine bug.
In ruby 1.8.6 on a different machine, it's ok.
Is this a known issue?
Sam
Hi,
I found a weird problem.
In ruby 1.8.5, I get the following result in irb.
BigDecimal.new("86.02").to_f #=> 86.2
I don't know if this is a ruby bug or machine bug.
In ruby 1.8.6 on a different machine, it's ok.
Is this a known issue?
Sam
I narrowed down the problem.
It has nothing to do with converting to float.
irb(main):023:0> BigDecimal.new("1.0234")
=> #<BigDecimal:b7efb05c,'0.1234E1',8(12)>
The internal representation is wrong.
Will upgrading ruby fix this problem?
On Oct 5, 1:02 pm, Sam Kong <sam.s.k...@gmail.com> wrote:
Hi,
I found a weird problem.
In ruby 1.8.5, I get the following result in irb.
BigDecimal.new("86.02").to_f #=> 86.2
I don't know if this is a ruby bug or machine bug.
In ruby 1.8.6 on a different machine, it's ok.Is this a known issue?
Sam
You don't say what patch level of 1.8.5 you are on. Using 1.8.5pl114
it works fine. However, likely it is a bug where the 0s immediately
following the decimal get eaten.
Upgrade your Ruby. Don't use 1.8.5.
Kirk Haines
On Mon, Oct 5, 2009 at 2:05 PM, Sam Kong <sam.s.kong@gmail.com> wrote:
Hi,
I found a weird problem.
In ruby 1.8.5, I get the following result in irb.
BigDecimal.new("86.02").to_f #=> 86.2
I don't know if this is a ruby bug or machine bug.
In ruby 1.8.6 on a different machine, it's ok.Is this a known issue?
I suspect so:
christopher@ubuntu:~$ ruby -v -rbigdecimal -e
'd=BigDecimal.new("1.0234"); p d; p d.to_f'
ruby 1.8.6 (2009-08-04 patchlevel 383) [x86_64-linux]
#<BigDecimal:7ff22e270380,'0.10234E1',18(18)>
1.0234
On Mon, Oct 5, 2009 at 1:15 PM, Sam Kong <sam.s.kong@gmail.com> wrote:
On Oct 5, 1:02 pm, Sam Kong <sam.s.k...@gmail.com> wrote:
Hi,
I found a weird problem.
In ruby 1.8.5, I get the following result in irb.
BigDecimal.new("86.02").to_f #=> 86.2
I don't know if this is a ruby bug or machine bug.
In ruby 1.8.6 on a different machine, it's ok.Is this a known issue?
Sam
I narrowed down the problem.
It has nothing to do with converting to float.irb(main):023:0> BigDecimal.new("1.0234")
=> #<BigDecimal:b7efb05c,'0.1234E1',8(12)>The internal representation is wrong.
Will upgrading ruby fix this problem?