Javascript Number toStringWithDelimiter()

Description

Javascript Number toStringWithDelimiter()


function insertThousandsDelimiters(string) {
  var splits = string.split('.');
  splits[0] = splits[0].replace(/(\d)(?=(\d\d\d)+(?!\d))/g, '$1,');
  return splits.join('.');
};

Number.prototype.toStringWithDelimiter = function() {
  return insertThousandsDelimiters(this + '');
};



PreviousNext

Related