Skip to content

Instantly share code, notes, and snippets.

@iamdbc
Created August 9, 2017 02:05
Show Gist options
  • Save iamdbc/937399d66d157d5b6b84b059a41ed818 to your computer and use it in GitHub Desktop.
Save iamdbc/937399d66d157d5b6b84b059a41ed818 to your computer and use it in GitHub Desktop.
functin formatMoney (value) {
if (!value) return '0';
var num = value.toString().split('.')[0];
var dot = value.toString().split('.')[1];
var num = (num || 0).toString(), result = '';
while (num.length > 3) {
result = ',' + num.slice(-3) + result;
num = num.slice(0, num.length - 3);
}
if (num) { result = num + result; }
if (dot) {
result = result + '.' + dot;
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment