[Tutor] Float and decimal spaces
sli1que at yahoo.com
Sat Aug 4 15:43:49 CEST 2007
--- Kent Johnson <kent37 at tds.net> wrote:
> Toon Pieton wrote:
> > Hey all!
> > My memory seem to have a horrible leak. How does
> one limit the amount of
> > decimal spaces for a float? I used to know that...
> > Example: not 5.398042156, but 5.4 (if I decide to
> have only one place).
> For printing, use %.1f :
> In : print '%.1f' % 5.398042156
> If you want to limit the precision of computations
> maybe the Decimal
> module would help.
> Tutor maillist - Tutor at python.org
You can try this:
>>> print '%.2f' % (test)
The number gives the number of precision after the
Moody friends. Drama queens. Your life? Nope! - their life, your story. Play Sims Stories at Yahoo! Games.
More information about the Tutor