[issue40206] Multiplying 4.6*100 will result in 459.99999999999994

2020-04-07 Thread Stefan Krah
Stefan Krah added the comment: You can also set the decimal.FloatOperation trap to avoid accidental errors: >>> from decimal import * >>> c = getcontext() >>> Decimal(4.6) * 100 Decimal('459.9644728632120') >>> c.traps[FloatOperation] = True >>> Decimal(4.6) * 100 Traceback (most

[issue40206] Multiplying 4.6*100 will result in 459.99999999999994

2020-04-06 Thread Rémi Lapeyre
Rémi Lapeyre added the comment: @Steven Yes that's true, I only meant that in the context of the issue where only the multiplication is used. FWIW Fraction also would have issues with e.g. trigonometric functions right? @ahmad, that's because you did Decimal(4.6) which first parse 4.6 as a f

[issue40206] Multiplying 4.6*100 will result in 459.99999999999994

2020-04-06 Thread ahmad dana
ahmad dana added the comment: Regarding the comment about the decimal point precision , and solving the issue with the decimal library, the following attachment shows you that the decimal Library did exactly the same behaviour -- Added file: https://bugs.python.org/file49040/Screen S

[issue40206] Multiplying 4.6*100 will result in 459.99999999999994

2020-04-06 Thread Steven D'Aprano
Steven D'Aprano added the comment: Rémi, it is not true that the Decimal module won't lose precision. It will. Decimal is not exact either, it is still a floating point format similar to float. py> Decimal(1)/3*3 Decimal('0.') The two major advantages of Decimal a

[issue40206] Multiplying 4.6*100 will result in 459.99999999999994

2020-04-06 Thread Eric V. Smith
Eric V. Smith added the comment: See https://docs.python.org/3.8/tutorial/floatingpoint.html -- nosy: +eric.smith resolution: -> not a bug stage: -> resolved status: open -> closed ___ Python tracker _

[issue40206] Multiplying 4.6*100 will result in 459.99999999999994

2020-04-06 Thread Rémi Lapeyre
Rémi Lapeyre added the comment: Hi ahmad, calculation with floating points in Python uses the IEE 754 (https://fr.wikipedia.org/wiki/IEEE_754) standard and will result in such quirks. If you want to not loose precision you can use the decimal module: >>> from decimal import Decimal >>> Decim

[issue40206] Multiplying 4.6*100 will result in 459.99999999999994

2020-04-06 Thread ahmad dana
New submission from ahmad dana : While we using python3.7 to do some number multiplication, we faced an issue with multiplying 4.6*100 which lead to strange output, the result was 459.94, while it should be something like 460.00 -- messages: 365860 nosy: ahmad dana priori