Nobuyoshi Nakada
5/6/2009 3:06:00 AM
Hi,
At Wed, 6 May 2009 10:01:54 +0900,
Samuel Lown wrote in [ruby-talk:335867]:
> >> ((30 / BigDecimal("1.16")) * BigDecimal("1.16")) == 30
> => false
> >> ((30 / BigDecimal("1.16")) * BigDecimal("1.16")).to_s
> => "30.0000000000000000000000002"
>
> I'm clearly missing something here as I thought BigDecimal was supposed
> to fix this type of thing.
BigDecimal is another kind of floating point number, which uses
decimal base instead of binary, but has finite digits.
Therefore, it is impossible to represent exactly a recurring
decimal theoretically.
--
Nobu Nakada