String to Float, without introducing errors
Peter J. Holzer
hjp-python at hjp.at
Sat Dec 17 16:45:12 EST 2022
On 2022-12-17 21:45:06 +0100, Paul St George wrote:
> It was the rounding rounding error that I needed to avoid (as Peter J.
> Holzer suggested). The use of decimal solved it and just in time. I
> was about to truncate the number, get each of the characters from the
> string mantissa, and then do something like this:
>
> 64550.727
>
> 64550 + (7 * 0.1) + (2 * 0.01) + (7 * 0.001)
That wouldn't have helped. In fact it would have made matters worse
because instead of a single rounding operation you now have nine!
hp
--
_ | Peter J. Holzer | Story must make more sense than reality.
|_|_) | |
| | | hjp at hjp.at | -- Charles Stross, "Creative writing
__/ | http://www.hjp.at/ | challenge!"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://mail.python.org/pipermail/python-list/attachments/20221217/60e8045c/attachment.sig>
More information about the Python-list
mailing list