Sep-28-2018, 08:35 AM
Sep-28-2018, 09:15 AM
No, this is not a bug: http://0.30000000000000004.com/
Sep-28-2018, 10:05 AM
I don't think it's a bug. It's just unique to python3.6.
You could use
You could use
round
:a="1.1" b="2.2" # Here the number of decimal places is the 2nd argument. x=round(float(a)+float(b), 2) print(x)
Sep-28-2018, 10:52 AM
(Sep-28-2018, 10:05 AM)Mr_Keystrokes Wrote: [ -> ]I don't think it's a bug. It's just unique to python3.6.It's not only unique to python3.6,see @DeaD_EyE link.
Basic Answers.
Quote:Because internally, computers use a format (binary floating-point) that cannot accurately represent a number like 0.1, 0.2 or 0.3 at all.
Python has Decimal module,then it work like excepted eg doing financial calculation.
>>> 0.4 - 0.1 0.30000000000000004 # Now it will be 0,3 >>> from decimal import Decimal >>> Decimal('0.4') - Decimal('0.1') Decimal('0.3') >>> print(Decimal('0.4') - Decimal('0.1')) 0,3