String to Float, without introducing errors
Chris Angelico
rosuav at gmail.com
Sat Dec 17 15:49:05 EST 2022
On Sun, 18 Dec 2022 at 07:46, Paul St George <email at paulstgeorge.com> wrote:
>
> Thanks to all!
> 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)
>
> Now I do not need to!
It sounds like fixed-point arithmetic might be a better fit for what
you're doing.
ChrisA
More information about the Python-list
mailing list