Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #10014

Re: Convert '165.0' to int

Date 2011-07-21 11:53 +0200
From Thomas Jollans <t@jollybox.de>
Subject Re: Convert '165.0' to int
References <j08rn1$mep$1@dough.gmane.org>
Newsgroups comp.lang.python
Message-ID <mailman.1318.1311242031.1164.python-list@python.org> (permalink)

Show all headers | View raw


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 '165.xyz' 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.

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Re: Convert '165.0' to int Thomas Jollans <t@jollybox.de> - 2011-07-21 11:53 +0200
  Re: Convert '165.0' to int Frank Millman <frank@chagford.com> - 2011-07-21 04:09 -0700

csiph-web