Created
August 9, 2017 02:05
-
-
Save iamdbc/937399d66d157d5b6b84b059a41ed818 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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