0
a = int(124.99999999999999) #14 Decimal Places
print(a)

#Output: 124
 
b = int(124.999999999999999) #15 Decimal Places
print(b)

#Output: 125

I would like to know the working behind this as the output remains 0 in the above code when 124 is replaced with 0 even with 15 decimal places of 9.

Elmo
  • 31
  • 3
  • 1
    Integer conversion is a red herring. `125.0 == 124.999999999999999` and `1.0 == 0.99999999999999999` – wjandrea Jun 08 '21 at 01:01
  • I think it has something to do with the typing of c++ when i was working on my toy programming language project i ended up dealing with all the numbers ( int or float ) as float in c++ and since there is built in cast between float an double in c++ an most of python interpreter have been made with c++ think that when you reach the 15 digit after the dot it is converted to double and since double is way too precise i might actually been decided by the python designer that from double to int python should be rounding to the biggest – Chris Golden Jun 08 '21 at 01:07

0 Answers0