Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
JS Regex: Adds thousands separator to a number.
// Adds the thousands separator
function numberWithThousands(x) {
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ".");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.