On Aug 9, 5:46 pm, Peter Otten <__pete...@web. dewrote:
Will Rocisky wrote:
I want my 76.1 to be rounded to decimal 80 and 74.9 to decimal 70.
How can I achieve that?
>help(round)
>
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.
>
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.
On Aug 9, 4:54 pm, John Machin <sjmac...@lexic on.netwrote:
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
Which would be correct if your goal was to restrain to
1 significant digit.
>
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.
Well, I can't read the OP's mind and the cases I HAVE encountered
are concerned about the number of significant digits. When
laboratories
report 3 digits, all my manipulations (ppm conversion, dividing
non-detect reporting limits by 2, comparison to TACO, etc. are
required to also have exactly 3 digits of significance).
>>print '%.2e' % 0.00000123456
1.23e-006
>>print '%.2e' % 123456
1.23e+005
>>print '%.2e' % 0.123000456
1.23e-001
It all depends on what the OP actually wants. He's free to ignore
my example.
Comment