I want to format a currency with NumberFormat of Intl and get the returned value with a space " " between the symbol and the number.
new Intl.NumberFormat('pt-br', { style: 'currency', currency: 'USD' }).format(12345)
// "US$12.345,00"
new Intl.NumberFormat('pt-br', { style: 'currency', currency: 'BRL' }).format(12345)
// "R$12.345,00"
What I want: "US$ 12.345,00", "R$ 12.345,00"
Any ideas?
You can use
replaceto further format the currency.Update
There is currently an issue with Intl.js where some browsers put a space between the currency and the value resulting in the output that OP wanted. In that case, the formatting above will result in 2 spaces (as seen in the comments below).
You can add on
.replace(/\s+/g, ' ')to replace multiple spaces with a single space. This will ensure that if a space was added by the browser due to the above issue, the final output will still have a single space as expected.