Skip to content

Instantly share code, notes, and snippets.

@smokinggoats
Created April 8, 2020 14:25
Show Gist options
  • Save smokinggoats/070240450631c839f36dbdf15c995771 to your computer and use it in GitHub Desktop.
Save smokinggoats/070240450631c839f36dbdf15c995771 to your computer and use it in GitHub Desktop.
Format any string to a simple number
function toNumber(num) {
return Number(String(num).replace(/\./g, ',').replace(/(.+),/g, '$1.').replace(/[^\d.]/g, '').trim())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment