3
0
mirror of https://github.com/reality/dbot.git synced 2024-12-25 04:02:39 +01:00

Merge pull request #79 from SamStudio8/master

numberFormat Snippet
This commit is contained in:
Luke Slater 2012-12-23 07:02:40 -08:00
commit 118c91549d

View File

@ -253,3 +253,13 @@ RegExp.prototype.url_regex = function() {
);
return reg;
}
Number.prototype.numberFormat = function(dec_places){
//TODO Possibly abstract this to some sort of localisation module in future?
var dec_point = '.';
var sep = ',';
var parts = this.toFixed(dec_places).toString().split(dec_point);
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, sep);
return parts.join(dec_point);
}