Nodejs Float Round roundMoney(decimals = 2)

Here you can find the source of roundMoney(decimals = 2)

Method Source Code

Number.prototype.roundMoney = Number.prototype.toObject || function roundMoney(decimals = 2) {
  return Number((Math.round(this + "e" + decimals) + "e-" + decimals));
};

Related

  1. round(precision)
    Number.prototype.round = function(precision) {
      var factor = Math.pow(10, precision || 0);
      return Math.round(this * factor) / factor;
    };
    
  2. round(precision)
    Number.prototype.round = function(precision){
      if (Object.isUndefined(precision)){
        return Math.round(this);
      precision = Math.pow(10, precision);
      return Math.round(this * precision) / precision;
    };
    
  3. round(precision)
    Number.prototype.round = function (precision) {
        precision = Math.pow(10, precision || 0);
        return Math.round(this * precision) / precision;
    };
    
  4. round5()
    Number.prototype.round5 = function() {
      return ((this)- (this % 5));
    
  5. roundDecimal()
    Number.prototype.roundDecimal = function() {
      return Math.roundDecimal(this);
    };
    
  6. roundNumber.prototype.round || (precision)
    Number.prototype.round = Number.prototype.round || function (precision) {
      return Math.round(this * Math.pow(10, (precision || 2))) / Math.pow(10, (precision || 2))
    
  7. roundTo()
    Number.prototype.roundTo = function() {
        return 32 * Math.round(this / 32);
    
  8. roundTo(num)
    Number.prototype.roundTo = function(num) {
      var resto = this%num;
      if (resto <= (num/2)) {
        return this-resto;
      } else {
        return this+num-resto;
    };
    
  9. roundToFixed(radix)
    Number.prototype.roundToFixed = function (radix) {
        var val = this;
        radix = radix || 0;
        val *= Math.pow(10, radix);
        val = Math.round(val);
        val /= Math.pow(10, radix);
        return val;
    };