Convert '165.0' to int

Chris Angelico rosuav at
Sun Jul 24 11:42:50 CEST 2011

On Sun, Jul 24, 2011 at 6:53 PM, Ben Finney <ben+python at> wrote:
> Frank Millman <frank at> writes:
>> I know I am flogging a dead horse here, but IMHO, '165', '165.',
>> '165.0', and '165.00' are all valid string representations of the
>> integer 165.[1]
> I disagree entirely. Once you introduce a decimal point into the
> representation, you're no longer representing an integer.
> (They might be the same *number*, but that's not saying the same thing.)

What's more, 1.311500322e+12 is a valid representation of a date/time,
according to a ridiculously broken game server I've worked with.
That's the number of milliseconds since 1970, stored as floating
point. I'm sure this makes sense to somebody...

Not all possible representations are equally sane. I'm with Ben;
'165.00' is not a string representation of an integer - but you CAN
take that string, validate it as representing a number that can be
represented as an integer, and evaluate what integer it is.

Chris Angelico

More information about the Python-list mailing list