[Tutor] Hoping for a brief explanation!
Mats Wichmann
mats at wichmann.us
Tue Aug 16 10:04:39 EDT 2022
On 8/16/22 06:04, Alan Gauld via Tutor wrote:
> On 16/08/2022 01:01, C S wrote:
>> Thank you!
>>
>>>>> print(10>9.999999999999999)
>> True
>>>>> print(10>9.9999999999999999)
>> False
>
> The brief explanation is that it is due to
> floating point rounding errors.
>
> If you don't understand that, you need to read
> the full explanation which can be found on Wikipedia
> (other resaources are available!)
>
>
> https://en.wikipedia.org/wiki/Round-off_error
>
>
> It is slightly baffling when you first come across
> it but it bites every programmer at some point and
> it is important to know about it and how to deal
> with it.
>
Add the explanation in Python's own docs:
https://docs.python.org/3/tutorial/floatingpoint.html
There is a different type in Python that you can use when you need to
keep exactness (for example when representing monetary transactions)
https://docs.python.org/3/library/decimal.html
More information about the Tutor
mailing list