0

I have numbers coming out of a text file that are milliseconds from the epoch represented as floats or integers. I would like to turn all of them into integers. First I just tried the following:

>>> int('1524960025000.0')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: invalid literal for int() with base 10: '1524960025000.0'

Okay that makes sense, so I guess what I'll do is:

>>> a = '1524960025000.0'
>>> b = '1524960025000'
>>> int(float(a))
1524960025000
>>> int(float(b))
1524960025000

Is there a more correct thing to do than this? This does what I want but for some reason feels clunky to me. I guess I'm just looking for confirmation that there isn't some better way to take any numeric looking strings and load them as integers.

Cheers.

nackjicholson
  • 4,557
  • 4
  • 37
  • 35

0 Answers0