Formatted Output - Floating Point Numbers

Tim Roberts timr at probo.com
Sun Nov 17 23:27:52 EST 2002


maximum_hops at yahoo.co.uk (David Marshall) wrote:

>Im new to python and I was wondering if anybody could tell me how to
>modify the output to only obtaiu 2 decimal places.
>
>the section of my program that needs modification
>
>display.divide(57,7) # I only want 2 decimal places returned
>
>I have a module called display and my function divide() returns the
>result of the two numbers divided. However, I only want this number to
>two decimal places.

The correct answer to your question has already been posted, but I want to
use this opportunity to point out a caution.

Your sample says you want "2 decimal places returned".  That is almost
NEVER what you really want to do.  You usually want to keep all the bits
you can, but only DISPLAY 2 decimal places.  The difference is important.
--
- Tim Roberts, timr at probo.com
  Providenza & Boekelheide, Inc.



More information about the Python-list mailing list