String to Float, without introducing errors

Grant Edwards grant.b.edwards at gmail.com
Sat Dec 17 16:21:34 EST 2022


On 2022-12-17, Chris Angelico <rosuav at gmail.com> 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)
>>
>> Now I do not need to!
>
> It sounds like fixed-point arithmetic might be a better fit for what
> you're doing.

Yes, fixed point (or decimal) is a better fit for what he's doing. but
I suspect that floating point would be a better fit for the problem
he's trying to solve.

--
Grant





More information about the Python-list mailing list