masaccio / numbers-parser

Python module for parsing Apple Numbers .numbers files
MIT License
208 stars 15 forks source link

Decimals and Floating point numbers #82

Closed mikez closed 6 months ago

mikez commented 6 months ago

I noticed, if I store 55.80 in Numbers, then cell.value becomes 55.800000000000004 in numbers-parser.

When is this rounding error introduced? Is it already in the IWA storage format itself or does it only occur later when creating Python floating points? If the latter, it might be nice to get out a decimal.Decimal or str or the like with the original IWA-value to prevent compounding rounding errors.

masaccio commented 6 months ago

The raw storage is D128 but that’s not always enough for some FP numbers.

cell.formatted_value returns the value of the cell as it appears in Numbers as a str. Part of the conversion is truncating the decimals to the maximum number of significant figures supported by numbers (15 digits).

mikez commented 6 months ago

Thank you. I don't understand the D128 encoding, but it sounds like it might be a floating point encoding. In that case, 15 digits sounds good knock on wood.