Created
April 3, 2015 09:01
-
-
Save lsauer/5a061e220d6bc1cf7435 to your computer and use it in GitHub Desktop.
JavaScript: money-string format with thousands separator
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
//lsauer.com, 2015 | |
var thousandSeparator = ','; | |
var inputNumber = 234234; | |
var fixedLength = 2 | |
parseFloat(inputNumber) | |
.toFixed(fixedLength) | |
.toString() | |
.split(/(.{3})/gm) | |
.filter(Boolean) | |
.join(thousandSeparator) | |
.replace(thousandSeparator + '.', '.') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment