Convert '165.0' to int
81282ed9a88799d21e77957df2d84bd6514d9af6 at myhashismyemail.com
Thu Jul 21 15:27:29 CEST 2011
On 07/21/2011 08:46 AM, Web Dreamer wrote:
> If you do not want to use 'float()' try:
This is right.
> But, the problem is the same as with int(float(x)), the integer number is
> still not as close as possible as the original float value.
> I would in fact consider doing this:
This is wrong, since there is a loss of information in the float cast:
Notice the last digit switched from a 3 to a 2? Floats in python don't
have arbitrary accuracy. You would need to import decimal and use it
for rounding to work properly.
More information about the Python-list