[Tutor] python precision output?

Andre Walker-Loud walksloud at gmail.com
Thu Dec 6 23:50:02 CET 2007


> if you want accuracy and are willing to sacrifice the total range of
> numbers that Python's IEEE754 double-precision floats give you, then
> use the decimal.Decimal class instead -- better precision, smaller
> range.
>
> however, if you wish to stick with floats, use the string format
> operator and tell it you want 17 places after the decimal point:
>
>>>> x=7./13
>>>> x
> 0.53846153846153844
>>>> str(x)
> '0.538461538462'
>>>> '%.17f' % x
> '0.53846153846153844'
>
> hope this helps!

This did the trick!  thanks,

Andre




> -- wesley
> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
> "Core Python Programming", Prentice Hall, (c)2007,2001
>     http://corepython.com
>
> wesley.j.chun :: wescpy-at-gmail.com
> python training and technical consulting
> cyberweb.consulting : silicon valley, ca
> http://cyberwebconsulting.com



More information about the Tutor mailing list