Created
September 24, 2012 14:05
-
-
Save darookee/3776117 to your computer and use it in GitHub Desktop.
Format Money in JavaScript
This file contains hidden or 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
| formatMoney = (n) -> | |
| DecimalSeparator = Number(1.2).toLocaleString().substr(1,1) | |
| n.toLocaleString().split(DecimalSeparator)[0] + DecimalSeparator + n.toFixed(2).split('.')[1]; |
This file contains hidden or 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
| function formatMoney(n) { | |
| var DecimalSeparator = Number("1.2").toLocaleString().substr(1,1); | |
| return n.toLocaleString().split(DecimalSeparator)[0] + DecimalSeparator | |
| + n.toFixed(2).split('.')[1]; | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See http://stackoverflow.com/a/149371 and http://stackoverflow.com/a/149150