Getting fractional part from a float without using string operations
james.harris.1 at googlemail.com
Thu Nov 20 16:47:59 CET 2008
On 20 Nov, 06:01, srinivasan srinivas <sri_anna... at yahoo.co.in> wrote:
> Yes it works for most of the cases. But it doesn't for the following case:
> >>> str(abs(int(1234567.89)-1234567.89))
Well, that is 0.89 or about as near to it as the calculation can
represent. Like other numbers 0.89 evidently cannot be exactly
represented as a float in binary. The nearest number above it is
This is not a Python issue but a result of storing numbers in floating
BTW, please post comments below existing ones rather than above them.
It is more familiar on Usenet and, as a consequence, easier to read.
More information about the Python-list