Skip to content

Instantly share code, notes, and snippets.

@lsauer
Created April 3, 2015 09:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lsauer/5a061e220d6bc1cf7435 to your computer and use it in GitHub Desktop.
Save lsauer/5a061e220d6bc1cf7435 to your computer and use it in GitHub Desktop.
JavaScript: money-string format with thousands separator
//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