Round a decimal number

John Hunter jdhunter at ace.bsd.uchicago.edu
Thu May 29 15:49:58 EDT 2003


>>>>> "Manuel" == Manuel  <manuelbastioni at tin.it> writes:

    Manuel> How I can round a decimal number?  Example:
    Manuel> 1.4463784692425 to 1.45

Do you really want to round the number, or just round the display of
number.  Normally, it's the latter

>>> print '%1.2f' % 1.4463784692425
1.45

See http://www.python.org/doc/current/lib/typesseq-strings.html for
details on string formatting.

If you want to round the number itself, it might be a good idea to
post here why you do, in case it's not a good idea and there are
better ways to do it (eg, in financial applications).

John Hunter





More information about the Python-list mailing list