Rounding off a positive number to the next nearest multiple of 5

前端 未结 7 727
我寻月下人不归
我寻月下人不归 2020-12-11 03:39

I need to round of a number (the input is guaranteed to be an integer & is positive) to the next multiple of 5.

I tried this:

int round = ((grade         


        
7条回答
  •  眼角桃花
    2020-12-11 04:12

    I have a function to round up:

    def next(number, base):
        temp = round(number / base) * base
        return temp
    

    you can use it for your case like this:

    next(grade[j], 5)
    

    and in function it will be:

    temp = round(67 / 5) * 5
    return temp #temp = 75
    

    some case not using round but using ceil

提交回复
热议问题