int('0.0') throws an exception
BPettersen at NAREX.com
Thu Jan 30 01:28:02 CET 2003
> From: Ragu Bharadwaj [mailto:Ragu.Bharadwaj at amphoracorp.com]
> Why is it that
> int('0') and int(0.0) are OK but int('0.0') throws an Exception?
It behaves exactly as documented (Library Ref. 2.1): "If the argument is
a string, it must contain a possibly signed decimal number representable
as a Python integer...". Basically, it is only doing a one-step
conversion (whereas "3.14" -> 3.14 -> 3 would be a two-step conversion).
You can easily get the functionality you expect by:
x = int(float('3.14'))
More information about the Python-list