results of division

Aahz aahz at
Thu Dec 9 15:52:56 CET 2004

In article <cp9o1v$ibq$1 at>,
Brad Tilley  <bradtilley at> wrote:
>What is the proper way to limit the results of division to only a few 
>spaces after the decimal? I don't need rocket-science like precision. 
>Here's an example:
>1.775 is as exact as I need to be and normally, 1.70 will do.

You have two options: use floating point and round manually or use the
new Decimal class and specify your precision.  However, if you restrict
your calculations, you will have errors after chaining more than one or
two operations.  Your best bet is to perform rounding only at the end of
your calculations, at which point you can either round the result
directly or round for display only (by using appropriate % formatting).
Aahz (aahz at           <*>

"19. A language that doesn't affect the way you think about programming,
is not worth knowing."  --Alan Perlis

More information about the Python-list mailing list