Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python 3 floating point rounding #328

Closed
hpourreza opened this issue Nov 11, 2016 · 2 comments
Closed

Python 3 floating point rounding #328

hpourreza opened this issue Nov 11, 2016 · 2 comments

Comments

@hpourreza
Copy link

When I run 2.2*55 in Python 3, I get 121.00000000000001 instead of 121.0 that is on the course website (01_numpy). I think the output on the course website is from Python 2 that prints 121.0.

@rgaiacs
Copy link
Contributor

rgaiacs commented Nov 13, 2016

@hpourreza Thanks for the issue. Could you send a pull request to fix it?

@neon-ninja
Copy link

neon-ninja commented Feb 1, 2017

See https://docs.python.org/3/tutorial/floatingpoint.html -
"Historically, the Python prompt and built-in repr() function would choose the one with 17 significant digits, 0.10000000000000001. Starting with Python 3.1, Python (on most systems) is now able to choose the shortest of these and simply display 0.1."

However, it seems I see the opposite behaviour, the only way to get 121.0 is to evaluate print(2.2*55) on python2. Any other condition (executed at prompt, or executed in python3) results in 121.00000000000001

print(2.2*55) on python 2.7.10 on ideone: http://ideone.com/WYcuze = 121.0
evaluate at prompt on python 2.7.10 on repl.it: https://repl.it/F26E/0 = 121.00000000000001
print(2.2*55) on python 3.4 on ideone: http://ideone.com/DCQgI6 = 121.00000000000001

joshkyh added a commit to joshkyh/python-novice-inflammation that referenced this issue Nov 12, 2017
maxim-belkin pushed a commit that referenced this issue Jul 17, 2018
zkamvar pushed a commit that referenced this issue Apr 21, 2023
Change weight from 55 to 60 kg to avoid numerical errors

In Python 3: (55 * 2.2) = 121.00000000000001
To circumvent related discussions, we change weight to 60.

Closes #328
Closes #339
Closes #429

Signed-off-by: Maxim Belkin <maxim.belkin@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants