Convert '165.0' to int

Thomas Jollans t at
Thu Jul 21 11:53:43 CEST 2011

On 21/07/11 11:31, Frank Millman wrote:
> Hi all
> I want to convert '165.0' to an integer.

Well, it's not an integer. What does your data look like? How do you
wish to convert it to int? Do they all represent decimal numbers? If so,
how do you want to round them? What if you get '' as input?
Should that raise an exception? Should it evaluate to 165? Should it use
base 36?

> 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?

What's wrong with this? It's relatively concise, and it shows exactly
what you're trying to do.

More information about the Python-list mailing list