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

前端 未结 7 722
我寻月下人不归
我寻月下人不归 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 03:58

    int mod = grades[j] % 5;
    int round = grades[j] - mod;
    if (mod > 0) {
        round += 5;
    }
    

提交回复
热议问题