views:

200

answers:

2

I am seeing very, VERY strange behavior when I run certain reports:

>> p = BigDecimal.new('0.1785990254E5')
=> #<BigDecimal:b649b978,'0.1785990254E5',16(16)>
>> q = BigDecimal.new('0.76149149E4')
=> #<BigDecimal:b64968d8,'0.76149149E4',8(16)>
>> p-q
=> #<BigDecimal:b6495ab4,'0.124498764E5',16(32)>
>> p.to_s
=> "17859.90254"
>> q.to_s
=> "7614.9149"
>> (p-q).to_s
=> "10244.98764"

If you notice, p.to_s and the BigDecimal's representation look consistent. Same with q and q.to_s. However, (p-q) has the string represented as '0.1244...' but comes out when formatted as "10244.98..." When I run this through 'number_to_currency' it actually displays the wrong number ($12,449.88) rather than the expected number--BUT ONLY on my RHEL 4 Box

+1  A: 

After looking at the versions, it appears I am running Ruby 1.8.5 on the RHEL box and Ruby 1.8.6 on my local box. I assume this would account for the problems? Strange problems indeed.

Update: Confirmed - Upgrade to 1.8.6 resolved the issues.

Mark S.
Quite possibly. It's certainly something you should fix before doing too much testing.
toholio
A: 
>> p = BigDecimal.new('0.1785990254E5')
=> #<BigDecimal:51c9e4,'0.1785990254E5',16(16)>
>> q = BigDecimal.new('0.76149149E4')
=> #<BigDecimal:518e98,'0.76149149E4',8(16)>
>> p-q
=> #<BigDecimal:516af8,'0.1024498764E5',16(32)>
>> (p-q).to_s
=> "0.1024498764E5"

on my handcompiled ruby 1.8.7/OSX

Sounds like they may have fixed a bug in the library in between - but the speed improvements alone are probably a good enough reason for upgrading (I feel you if you're stuck maintaining an unupgradeable app tho)

I'm a little bit confused as to why you're trying to display 0.1024498764E5 as currency.

hiffy