I have a piece of code as follows:
var x = 1000;
x = x.toLocaleString('vi', {style : 'currency', currency : 'VND'});
console.log(x);
I expected output is:
1.000đ
But the actual output is:
đ1.000
Can anyone help me? thank a lot.
The Intl.NumberFormat object enables language-sensitive number formatting.
JavaScript numbers can be formatted in different ways like commas, currency, etc. You can use the toFixed() method to format the number with decimal points, and the toLocaleString() method to format the number with commas and Intl. NumberFormat() method to format the number with currency.
You can use format from other country as below:
var x = 1000;
x = x.toLocaleString('it-IT', {style : 'currency', currency : 'VND'});
console.log(x);
You can use Intl.NumberFormat
See more
console.log(new Intl.NumberFormat('vi-VN', { style: 'currency', currency: 'VND' }).format(1000));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With