[Tutor] Rounding number
rabidpoobear at gmail.com
Mon Mar 19 07:22:49 CET 2007
Per Jr. Greisen wrote:
> I use the method from math in order to round off the number:
> import math
> a = 1.39999
> b = round(a,3)
> which equals gives
> is it possible to have the rounding such that
> b = 1.400
Trailing zeroes aren't significant values so the computer won't store it.
This rounding works when the rounded values don't have trailing zeroes,
It's possible to add these zeroes using string formatting, when you want
to display them.
>>> "%.3f" % 1.4
See http://docs.python.org/lib/typesseq-strings.html for more
information on string formatting operations.
More information about the Tutor