Skip to content

Instantly share code, notes, and snippets.

@scottwb
Created February 11, 2011 04:10
Show Gist options
  • Save scottwb/821904 to your computer and use it in GitHub Desktop.
Save scottwb/821904 to your computer and use it in GitHub Desktop.
Rails-like number_with_delimiter in javascript
Number.prototype.number_with_delimiter = function(delimiter) {
var number = this + '', delimiter = delimiter || ',';
var split = number.split('.');
split[0] = split[0].replace(
/(\d)(?=(\d\d\d)+(?!\d))/g,
'$1' + delimiter
);
return split.join('.');
};
@sergio1990
Copy link

Thank you for sharing! This is exactly what I want.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment