Skip to content

Instantly share code, notes, and snippets.

@heymexa
Created September 18, 2014 07:49
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save heymexa/0e8c20b85c52d4e7f3b9 to your computer and use it in GitHub Desktop.
Save heymexa/0e8c20b85c52d4e7f3b9 to your computer and use it in GitHub Desktop.
/**
* @param {number} sum
* @returns {string}
* @example
* 1234567 -> 1 234 567
*/
function formatNumber (number) {
return number.toString().replace(/(\d)(?=(\d{3})+([\D]|$))/g, '$1 ');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment