Skip to content

Instantly share code, notes, and snippets.

@rochabianca
Created January 23, 2019 12:56
Show Gist options
  • Save rochabianca/eee88b6751dc464301def0f14da4f738 to your computer and use it in GitHub Desktop.
Save rochabianca/eee88b6751dc464301def0f14da4f738 to your computer and use it in GitHub Desktop.
format a number without putting decimals (something like that)
let num = 24674
const formattedNum = num.toFixed(0).replace(/(\d)(?=(\d{3})+$)/g, "$1.") // if you want to use commas instead of dots, you can
// replace the "$1." to "$1,"
console.log(formattedNum) // 24.674
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment