Mike Davis wrote:
> 12345678.123      gets converted correctly to 12345678.123 and,
> 12345678.1234     gets converted correctly to 12345678.1234 even,
> 12345678.12345678 gets converted correctly to 12345678.12345678
> 
> As soon as my IntegerPart exceeds 8 digits, the FracPart is incorrect
> (rounded) regardless of how many digits are displayed.
> 
> Bottom line is this has to do with rounding.  But why does this only
> happen when the IntegerPart exceeds 8 digits.

I think the problem is not that the integer part exceeds 8 digits, but
that the total number of digits (integer and fractional part) exceeds
about 16 digits.  A double can only hold a certain number of bits of
precision (I think 52, as you pointed out), which works out to about 16
decimal digits.  It doesn't matter where the decimal point is within
those 16 digits.  You'll find (if I'm correct), that numbers like
1234567891234.56 will work ok, since there's a total of less than 16
digits, even though the integer part is more than 8 digits.  As for a
workaround, there's not much you can do.  If you need more than 16
digits of precision, you'll need to store your numbers in something
other than a double, but you'll need to do a lot of work to write code
to do arithmetic on your new type of number.
--Mark

Reply via email to