Floating point bug?
Jeff Schwab
jeff at schwabcenter.com
Thu Feb 14 04:11:31 EST 2008
Dennis Lee Bieber wrote:
> On Wed, 13 Feb 2008 17:49:08 -0800, Jeff Schwab <jeff at schwabcenter.com>
> declaimed the following in comp.lang.python:
>
>> If you need a pretty string for use in code:
>>
>> >>> def pretty_fp(fpnum, prec=8):
>> ... return ('%.8f' % fpnum).rstrip('0')
>> ...
>> >>> pretty_fp(0.3)
>> '0.3'
>>
>
> What's wrong with just
>
> str(0.3)
Nothing!
> that's what "print" invokes, whereas the interpreter prompt is using
>
> repr(0.3)
Thanks for pointing that out.
More information about the Python-list
mailing list