W
Will Rocisky
I want my 76.1 to be rounded to decimal 80 and 74.9 to decimal 70.
How can I achieve that?
How can I achieve that?
I want my 76.1 to be rounded to decimal 80 and 74.9 to decimal 70.
How can I achieve that?import decimal
[decimal.Decimal(int(round(x, -1))) for x in (76.1, 74.9)] [Decimal("80"), Decimal("70")]
Will said:I want my 76.1 to be rounded to decimal 80 and 74.9 to decimal 70.
How can I achieve that?
Will said:I want my 76.1 to be rounded to decimal 80 and 74.9 to decimal 70.
How can I achieve that?
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.
... print "%r --> %r" % (f, round(f, -1))
...
74.900000000000006 --> 70.0
75.0 --> 80.0
75.099999999999994 --> 80.0
Peter
print int((n+5)/10)*10I want my 76.1 to be rounded to decimal 80 and 74.9 to decimal 70.
How can I achieve that?
8e+01I want my 76.1 to be rounded to decimal 80 and 74.9 to decimal 70.
How can I achieve that?
2e+002But:
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.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.