Does 'int' in Python 3.6 round backwards only? | Sololearn: Learn to code for FREE!

+2

Does 'int' in Python 3.6 round backwards only?

For example, I'm using int in my code and it's turning 2/3*100 into 66 rather than 67... But why?

2/1/2020 4:47:25 AM

Zaed _

6 Answers

New Answer

+6

a oneliner can clear the case https://code.sololearn.com/c1VN1k1Cvk9p/?ref=app

+5

Here are some interesting sources for the float inaccuracy problem. It's weekend, so we have time to dive in it. https://www.geeksforgeeks.org/floating-point-error-in-python/ https://docs.python.org/3/tutorial/floatingpoint.html https://0.30000000000000004.com/ https://floating-point-gui.de/languages/python/

+4

Yes,it only gives you the value backwards,even if your value is 66.99 ,if you want forward no you can use "ceil" function from math module

+4

Oma Falk, thank you for oyur sample. I have extended it with floor() and ceil(). https://code.sololearn.com/cPjC9CFr1DSv/?ref=app

+2

Lothar perfect!

+2

I want to add a little detail: If you string up enough 9 in the decimals, it will be rounded up! https://www.sololearn.com/discuss/2149084/?ref=app