Round integers to the nearest 10

后端 未结 7 1701
孤街浪徒
孤街浪徒 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:09

    Slightly simpler:

    def round_int(x):
        return 10 * ((x + 5) // 10)
    

提交回复
热议问题