How to round a floating point to nearest 10?

Will Rocisky geekmoth at gmail.com
Sat Aug 9 07:51:09 EDT 2008


On Aug 9, 5:46 pm, Peter Otten <__pete... at web.de> wrote:
> 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.
>
> >>> for f in 74.9, 75.0, 75.1:
>
> ...     print "%r --> %r" % (f, round(f, -1))
> ...
> 74.900000000000006 --> 70.0
> 75.0 --> 80.0
> 75.099999999999994 --> 80.0
>
> Peter

thankssss



More information about the Python-list mailing list