How to round a floating point to nearest 10?

John Machin sjmachin at lexicon.net
Sat Aug 9 17:54:03 EDT 2008


On Aug 10, 1:19 am, Mensanator <mensana... at aol.com> wrote:
> On Aug 9, 6:31 am, Will Rocisky <geekm... at gmail.com> wrote:
>
> > I want my 76.1 to be rounded to decimal 80 and 74.9 to decimal 70.
> > How can I achieve that?
> >>> print '%.0e' % 74.9
> 7e+01
> >>> print '%.0e' % 76.1
>
> 8e+01

But:
>>> print '%.0e' % 176.1
2e+002

Giving the Subject ("How to round a floating point to nearest 10?"),
there's a strong presumption that the OP would want the answer to be
180, not 200.



More information about the Python-list mailing list