Skip to content

@Lobstrosity /commafy.1.js
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
commafy
String.prototype.commafy = function () {
return this.replace(
/^(-?\d+)(\d{3}(\.\d+)?)$/,
function (_, a, b) {
return a.commafy() + ',' + b;
}
);
};
Number.prototype.commafy = function () {
return this.toString().commafy();
};
'-1234567.89'.commafy()
'-1234'.commafy() + ',' + '567.89'
'-1'.commafy() + ',' + '234' + ',' + '567.89'
'-1' + ',' + '234' + ',' + '567.89'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.