In Ruby 2.2.0, why does:
BigDecimal.new(34.13985572755337, 9)
equal 34.0
but
BigDecimal.new(34.13985572755338, 9)
equal 34.1398557
?
Note that I am running this on a 64 bit machine.
In Ruby 2.2.0, why does:
BigDecimal.new(34.13985572755337, 9)
equal 34.0
but
BigDecimal.new(34.13985572755338, 9)
equal 34.1398557
?
Note that I am running this on a 64 bit machine.
Initialize with Strings Instead of Floats
In general, you can't get reliable behavior with Floats. You're making the mistake of initializing your BigDecimals with Float values instead of String values, which introduces some imprecision right at the beginning. For example, on my 64-bit system:
This is one of those cases where the internal representation of the arguments matter. Therefore, your mileage will vary depending on how you initialize your object.