Round integers to the nearest 10

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

    if you want the algebric form and still use round for it it's hard to get simpler than:

    interval = 5
    n = 4
    print(round(n/interval))*interval
    

提交回复
热议问题