3
0
mirror of https://github.com/reality/dbot.git synced 2024-12-24 11:42:36 +01:00

numberFormat snippet

This commit is contained in:
Sam Nicholls 2012-12-23 15:01:07 +00:00
parent b1073e615b
commit fcf13daf43

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);
}