Round to the nearest 500, Python

后端 未结 3 1773
醉酒成梦
醉酒成梦 2021-02-02 12:54

I\'m looking to find a way to round up to the nearest 500.I\'ve been using:

math.ceil(round(8334.00256 + 250, -3))

Whereby I have a value from

3条回答
  •  爱一瞬间的悲伤
    2021-02-02 13:15

    Maybe something like this:

    round(float(x) / 500) * 500
    

    The "float" conversion is unnecessary if you are using Python 3 or later, or if you run the statement from __future__ import division for sane integer division.

提交回复
热议问题