This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: calculation not working properly
Type: Stage: resolved
Components: Windows Versions: Python 3.7
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: hwk_un1te, matrixise, paul.moore, steve.dower, steven.daprano, tim.golden, xtreak, zach.ware
Priority: normal Keywords:

Created on 2018-10-05 15:54 by hwk_un1te, last changed 2022-04-11 14:59 by admin. This issue is now closed.

File name Uploaded Description Edit
Capture.PNG hwk_un1te, 2018-10-05 15:54
Messages (5)
msg327143 - (view) Author: Cem (hwk_un1te) Date: 2018-10-05 15:54
as shown below for some reason 15.06 + 5 results in an addition of 0.0000002 and i want to know why its an bug or something im doing wrong but below it i tried it with 15.07 it works
msg327145 - (view) Author: Stéphane Wirtel (matrixise) * (Python committer) Date: 2018-10-05 16:13
because you have the round with the float type. 

you could use the decimal module with Decimal

In [1]: import decimal

In [2]: decimal.Decimal('15.06') + 5
Out[2]: Decimal('20.06')
msg327146 - (view) Author: Stéphane Wirtel (matrixise) * (Python committer) Date: 2018-10-05 16:15
and you can read this link where we explain the limits of the float type:
msg327148 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2018-10-05 16:21
Thanks for the report but I think is a known limitation with floating points and this page explains it well : . Using round will be helpful in your situation to round the output to 2 decimal places. I think the issue is also not predictable and a below example on Python 3 is similar to your case. I think this is not a bug in Python but a known behavior that is also present in a lot of other languages.

>>> 0.1+0.2
>>> 0.2+0.2
>>> 0.2+0.3
>>> 0.2+0.4
msg327153 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2018-10-05 17:12
For future reference, please don't post unnecessary screen shots and images. Code is text, please copy and paste it as text, not as pixels.

Images make it difficult or impossible for the blind and visually impaired to contribute.
Date User Action Args
2022-04-11 14:59:06adminsetgithub: 79088
2018-10-05 17:12:13steven.dapranosetnosy: + steven.daprano
messages: + msg327153
2018-10-05 16:58:00zach.waresetstatus: open -> closed
resolution: not a bug
2018-10-05 16:21:34xtreaksetnosy: + xtreak
messages: + msg327148
2018-10-05 16:15:42matrixisesetstatus: closed -> open

messages: + msg327146
2018-10-05 16:13:42matrixisesetstatus: open -> closed

nosy: + matrixise
messages: + msg327145

stage: resolved
2018-10-05 15:54:54hwk_un1tecreate