Who told str() to round my int()'s!!!
AWasilenko at gmail.com
Sat Aug 11 19:10:05 CEST 2007
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. I will worry about long FP values in previous steps. I still
find it very disturbing that str() is doing this AND it is
undocumented in all of my books.
> Use string formatting to tell the number of digits you want to see:
> In : '%.56f' % 0.1
> Out: '0.10000000000000000555111512312578270211815834045410156250'
The book I used to learn Python never introduced string formatting, I
suppose I will have to use another and learn it if that is the only
More information about the Python-list