python rounding problem.
Erik Max Francis
max at alcyone.com
Sun May 7 03:42:01 EDT 2006
chun ping wang wrote:
> Hey i have a stupid question.
>
> How do i get python to print the result in only three decimal place...
>
> Example>>> round (2.995423333545555, 3)
> 2.9950000000000001
>
> but i want to get rid of all trailing 0's..how would i do that?
Floating point arithmetic is inherently imprecise. This is not a Python
problem.
If you want to print it to only three digits, then use something like::
>>> '%.3f' % 2.995423333545555
'2.995'
--
Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/
San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
Whoever contends with the great sheds his own blood.
-- Sa'di
More information about the Python-list
mailing list