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.

classification
Title: Error in Multiplication
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.9
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: M1kE, eric.smith, steven.daprano
Priority: normal Keywords:

Created on 2021-12-02 16:39 by M1kE, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (3)
msg407537 - (view) Author: Mukesh (M1kE) Date: 2021-12-02 16:39
I've tried various methods to multiply some numbers but every time I get an unsatisfying result when I try to evaluate 48*1.2 or 41*1.2 or 51*1.4 etc. For example if I run

import math
NUM3 = eval(input("Your Input: "))
print(NUM3)

Output:
Your Input: 51*1.4
71.39999999999999

Now it should give me a straight 71.4 but instead it's giving 71.39999999999999

It's not an issue with the version of python that I'm using cause I've already tried it on various versions.
msg407538 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2021-12-02 16:43
This isn't a bug, it's a function of the IEEE-754 double precision floating point type that python uses. See: https://docs.python.org/3/tutorial/floatingpoint.html

You might want to consider the decimal module, although that will also have limitations.
msg407563 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2021-12-03 00:25
https://docs.python.org/3/faq/design.html#why-am-i-getting-strange-results-with-simple-arithmetic-operations
History
Date User Action Args
2022-04-11 14:59:53adminsetgithub: 90124
2021-12-03 00:25:29steven.dapranosetnosy: + steven.daprano
messages: + msg407563
2021-12-02 16:43:04eric.smithsetstatus: open -> closed

nosy: + eric.smith
messages: + msg407538

resolution: not a bug
stage: resolved
2021-12-02 16:39:50M1kEcreate