Created
May 24, 2015 16:32
-
-
Save radist2s/8a6cdaaeda6c4c6996b5 to your computer and use it in GitHub Desktop.
Format Money
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
window.formatMoney = function formatMoney(money) { | |
money = parseInt(money) | |
money = isFinite(money) ? money : 0 | |
return String(money).replace(/./g, function(c, i, a) { | |
return i && c !== '.' && ((a.length - i) % 3 === 0) ? ' ' + c : c | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment