Who told str() to round my int()'s!!!

Marc 'BlackJack' Rintsch bj_666 at gmx.net
Sat Aug 11 15:01:15 EDT 2007


On Sat, 11 Aug 2007 17:10:05 +0000, Adam W. wrote:

> On Aug 11, 12:53 pm, Marc 'BlackJack' Rintsch <bj_... at gmx.net> wrote:
>> If `str()` would not round you would get very long numbers because of the
>> inaccuracies of floating point values.  I know Python is lying when 0.1
>> prints as 0.1, but do you really want to see
>> 0.10000000000000000555111512312578270211815834045410156250 instead?
> 
> I want str() to convert whatever I give it to a string and do nothing
> else.

But those long numbers are very disturbing and nobody wants them as usual
string representation.  Most programming languages "lie" at this point to
the user so it would be very unexpected too.

> I will worry about long FP values in previous steps.

What do you mean here?  Have you looked at the example above?  That is the
closest you get to 0.1 -- there's no way to round the floating point
value, it can only be done by converting to `str()`.

Ciao,
	Marc 'BlackJack' Rintsch



More information about the Python-list mailing list