Convert '165.0' to int
Frank Millman
frank at chagford.com
Thu Jul 21 05:31:56 EDT 2011
Hi all
I want to convert '165.0' to an integer.
The obvious method does not work -
>>> x = '165.0'
>>> int(x)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: invalid literal for int() with base 10: '165.0'
If I convert to a float first, it does work -
>>> int(float(x))
165
>>>
Is there a short cut, or must I do this every time (I have lots of them!) ?
I know I can write a function to do this, but is there anything built-in?
Thanks
Frank Millman
More information about the Python-list
mailing list