From: mathew
Date: 2005-12-17T07:12:45+09:00
Subject: Re: Using Float For Currency
Joe Van Dyk wrote:
>On 12/12/05, mental@rydia.net wrote:
>>If you're doing anything that matters, don't use floats for
>>currency. There are a lot of really nasty subtle issues that will
>>lose money between the cracks.
[...]
>
> What cracks can I lose money through?
It's not just that; your program logic can also behave unexpectedly. e.g.
irb> 1.20 - 1.00 == 0.20
=> false
Use BigDecimal for currency. I've just finished some new Rdoc
documentation for it which will hopefully be added to ruby-doc.org and
the 1.9 release, and can forward you a copy if you like.
mathew
--
My parents went to the lost kingdom of Hyrule
and all I got was this lousy triforce.