How to round a floating point to nearest 10?

John Machin sjmachin at lexicon.net
Sat Aug 9 07:45:48 EDT 2008


On Aug 9, 9:31 pm, Will Rocisky <geekm... at gmail.com> wrote:
> 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")]
>>>





More information about the Python-list mailing list