python rounding problem.

Tim Roberts timr at probo.com
Thu May 11 01:58:34 EDT 2006


"chun ping wang" <cablepuff at hotmail.com> 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?

Your "problem" is not a problem in real programs -- it's only a problem
because of the way the interactive interpreter works:

C:\WINDOWS>python
Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> round(2.99543322,3)
2.9950000000000001
>>> print round(2.99543322,3)
2.995
>>>

-- 
- Tim Roberts, timr at probo.com
  Providenza & Boekelheide, Inc.



More information about the Python-list mailing list