[removed] Round up to the next multiple of 5

后端 未结 8 927
[愿得一人]
[愿得一人] 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:14

    // round with precision

    var round = function (value, precision) {
        return Math.round(value * Math.pow(10, precision)) / Math.pow(10, precision);
    };
    

    // round to 5 with precision

    var round5 = (value, precision) => {
        return round(value * 2, precision) / 2;
    }
    
    0 讨论(0)
  • 2020-12-02 10:19
    voici 2 solutions possibles :
    y= (x % 10==0) ? x : x-x%5 +5; //......... 15 => 20 ; 37 => 40 ;  41 => 45 ; 20 => 20 ; 
    
    z= (x % 5==0) ? x : x-x%5 +5;  //......... 15 => 15 ; 37 => 40 ;  41 => 45 ; 20 => 20 ;
    

    Regards Paul

    0 讨论(0)
提交回复
热议问题