0

I'm trying to cast a large float to an int in python. A simple example is: int(1648083600123123000.0)

Why does this get cast to 1648083600123122944 instead of 1648083600123123000 ?

Mark Dickinson
  • 29,088
  • 9
  • 83
  • 120
Lost Crotchet
  • 1,270
  • 12
  • 17
  • While this question [floating point in python gives a wrong answer](https://stackoverflow.com/questions/10403434/floating-point-in-python-gives-a-wrong-answer) is not a perfect duplicate, the root cause is the same and the accepted answer is likely your best solution. – shriakhilc Mar 24 '22 at 12:58
  • 3
    The float that you're passing to `int` _already_ has value `1648083600123122944.0` (try for example printing `format(1648083600123123000.0, ".0f")`). The `int` conversion isn't changing the value at all - it's just changing the type. – Mark Dickinson Mar 24 '22 at 13:25

0 Answers0