472,139 Members | 1,743 Online

# RE: How to round a floating point to nearest 10?

>>round(76.1, -2)
100.0
>>round(76.1, -1)
80.0
>>round(76.1)
76.0
>>
builtin function round, will work for you......
Help on built-in function round in module __builtin__:
round(...)
round(number[, ndigits]) -floating point number

Round a number to a given precision in decimal digits (default 0 digits).
This always returns a floating point number. Precision may be negative.

good luck..
Edwin

-----Original Message-----
From: py************************************************ **@python.org
[mailto:py***************************************** *********@python.org]
On Behalf Of John Machin
Sent: Saturday, August 09, 2008 5:54 PM
To: py*********@python.org
Subject: Re: How to round a floating point to nearest 10?
On Aug 10, 1:19 am, Mensanator <mensana...@aol.comwrote:
On Aug 9, 6:31 am, Will Rocisky <geekm...@gmail.comwrote:
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.
--
http://mail.python.org/mailman/listinfo/python-list
The information contained in this message and any attachment may be
proprietary, confidential, and privileged or subject to the work
product doctrine and thus protected from disclosure. If the reader
of this message is not the intended recipient, or an employee or
agent responsible for delivering this message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
immediately by replying to this message and deleting it and all
copies and backups thereof. Thank you.
Aug 9 '08 #1
0 1460

### This discussion thread is closed

Replies have been disabled for this discussion.