[Tutor] Hoping for a brief explanation!

Peter Otten __peter__ at web.de
Wed Aug 17 02:17:04 EDT 2022


On 16/08/2022 16:04, Mats Wichmann wrote:

> 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

You may run into counterintuitive results with that, too.

 >>> from decimal import Decimal, getcontext
 >>> getcontext().prec = 3
 >>> x = Decimal("0.9999")
 >>> x < 1
True
 >>> x * x < 1
False

There is no numerical type that "just works" like you learned at school.


More information about the Tutor mailing list