Skip to content

Instantly share code, notes, and snippets.

@ValchanOficial
Created September 24, 2024 13:27
Show Gist options
  • Save ValchanOficial/6dc1cd4203101d38b3c93f865313c92e to your computer and use it in GitHub Desktop.
Save ValchanOficial/6dc1cd4203101d38b3c93f865313c92e to your computer and use it in GitHub Desktop.
[Javascript][NumberFormat][toLocaleString][currency]
// Info: \u00a0 é o   que é o espaço sem quebra
const number = 123456.789;
console.log(new Intl.NumberFormat('pt-BR', { style: 'currency', currency: 'BRL' }).format(number).replace(/\u00a0/g, ' '));
console.log(Number(number).toLocaleString('pt-BR', { style: 'currency', currency: 'BRL' }).replace(/\u00a0/g, ' '))
// Output: "R$ 123.456,79"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment