Nodejs Float Round decRound(num, decimals)

Here you can find the source of decRound(num, decimals)

Method Source Code

// create empty class for adding static methods not in the Math Object
function MyMath () {}

// new static round method with decimal specification
MyMath.decRound = function(num, decimals){
    return Math.round(num*Math.pow(10,decimals))/Math.pow(10,decimals);
}

Related

  1. roundTo(num, dec)
    Math.roundTo = function (num, dec) {
      return Math.round(num * Math.pow(10, dec)) / Math.pow(10, dec);
    };
    
  2. round(value)
    Util.round = function(value) {
      return new Number((new Number(value)).toFixed(2));
    };
    
  3. roundTo (num, to)
    Math.ceilTo = function roundTo (num, to) {
        if (num < to) {
            return to;
        var amount = to * Math.ceil(num / to);
        if (amount === 0) {
            amount = to;
        return amount;
    ...
    
  4. roundTo(num, to)
    Math.roundTo = function roundTo (num, to) {
        if (num < to / 2) {
            return 0;
        var amount = to * Math.round(num / to);
        if (amount === 0) {
            amount = to;
        return amount;
    ...
    
  5. $round(fractionalDigits)
    Number.prototype.$round = function(fractionalDigits) {
        return parseFloat(this.toFixed(fractionalDigits));
    };
    
  6. ToRound(digits)
    Number.prototype.ToRound = function (digits) {
        if (digits < 0 || digits > 10)
            return this;
        var pow10 = Math.pow(10, digits);
        return Math.round(this * pow10) / pow10;
    };
    
  7. round()
    Number.prototype.round = function() {
      return Math.round(this);
    };
    
  8. round()
    Number.prototype.round = function() {
      return Math.round(this);
    };