[removed] Round up to the next multiple of 5

后端 未结 8 959
[愿得一人]
[愿得一人] 2020-12-02 09:39

I need a utility function that takes in an integer value (ranging from 2 to 5 digits in length) that rounds up to the next multiple of 5 instead of the

8条回答
  •  抹茶落季
    2020-12-02 10:12

    This will do the work:

    function round5(x)
    {
        return Math.ceil(x/5)*5;
    }
    

    It's just a variation of the common rounding number to nearest multiple of x function Math.round(number/x)*x, but using .ceil instead of .round makes it always round up instead of down/up according to mathematical rules.

提交回复
热议问题