Rohit Rai
Rohit Rai

Reputation: 1

Well how is Python handling division of 2 integers, it's confusing

rohit@rohit-ubuntu:~$ python3
Python 3.12.3 (main, Apr 10 2024, 05:33:47) [GCC 13.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 14 / 60
0.23333333333333334
>>> 51 / 3600
0.014166666666666666

So I was trying to divide 14 by 60 and I did it on pen and paper and ofcourse it was 0.233... and similarly for 51 by 3600 it was 0.0141666...

But when I tried doing it using the Python interpreter I got the above results, which I don't understand. First of all in the first case there is 17 digits after the decimal point and in the second case it is 18 digits. Also the first one ends in 4 (I don't know why) and if it does then why don't the second one also ends in 7 and not 6?

So I was expecting the result to be, first equal number of digits after the decimal point in both cases and the result of first one to be 0.23333333333333332 and second one to be 0.01416666666666667, given Python follows standard rounding technique?

Upvotes: 0

Views: 31

Answers (0)

Related Questions