This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author nathan snobelen
Recipients nathan snobelen
Date 2016-08-05.21:57:17
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1470434238.47.0.90762321591.issue27697@psf.upfronthosting.co.za>
In-reply-to
Content
Hi, I've noticed a bug in int() when converting a specific range of numbers it will incorrectly round the last digit down.

We have some payment code which formats numbers for processing in our system and we noticed that the payment of 1108431.38 was dropped by a penny to 1108431.37.  I looked into it and found that it is dropped when it is multiplied by 100 (to remove the decimal) and then converted back to an int.

Note, this bug only applies to the following range of numbers: 1108431.38 - 1108431.41.  Any other number I tried was unaffected. 

The following code will replicate the bug:

import math

amount1 = 110843138.0
amount2 = 1108431.38 * 100

print "Orig amount1 " + str(amount1)
print "Orig amount2 " + str(amount2)

print "Converted amount1 " + str(int(amount1))
print "Converted amount2 " + str(int(amount2))

Try it, and you will see that "amount1" remains correct, but "amount2" is affected.  Multiplying by 100 seems to trigger it... however note that even after it has been multiplied by 100 it is still correct... it's only when you then apply the int() function that the penny drops.

So it would appear that something is wrong in the int() function.

Cheers,
Nathan
History
Date User Action Args
2016-08-05 21:57:18nathan snobelensetrecipients: + nathan snobelen
2016-08-05 21:57:18nathan snobelensetmessageid: <1470434238.47.0.90762321591.issue27697@psf.upfronthosting.co.za>
2016-08-05 21:57:18nathan snobelenlinkissue27697 messages
2016-08-05 21:57:17nathan snobelencreate