Round integers to the nearest 10

后端 未结 7 1676
孤街浪徒
孤街浪徒 2020-11-27 17:45

I am trying to round integers in python. I looked at the built-in round() function but it seems that that rounds floats.

My goal is to round integers to the closest

7条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-27 18:21

    Actually, you could still use the round function:

    >>> print round(1123.456789, -1)
    1120.0
    

    This would round to the closest multiple of 10. To 100 would be -2 as the second argument and so forth.

提交回复
热议问题