472,139 Members | 1,743 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,139 software developers and data experts.

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.
If you have received this communication in error, please notify me
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.

Similar topics

11 posts views Thread by Russell E. Owen | last post: by
6 posts views Thread by Jef Driesen | last post: by
14 posts views Thread by Nils Grimsmo | last post: by
10 posts views Thread by TomislaW | last post: by
9 posts views Thread by Ronald W. Roberts | last post: by
70 posts views Thread by Robert Gamble | last post: by
7 posts views Thread by kkmigas | last post: by
7 posts views Thread by Will Rocisky | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.