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.
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.
Share Improve this question asked Jun 23, 2016 at 8:06 ThiepLVThiepLV 1,2793 gold badges10 silver badges22 bronze badges 1- Perhaps github.com/willsp/polyfill-Number.toLocaleString-with-Locales – mplungjan Commented Jun 23, 2016 at 8:09
4 Answers
Reset to default 6You 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));
var x = 1000;
x = x.toLocaleString('en-US', {style : 'currency', currency : 'VND'});
console.log(x);
const money = 123456789.987654321;
const config = { style: 'currency', currency: 'VND', maximumFractionDigits: 9}
const formated = new Intl.NumberFormat('vi-VN', config).format(money);
console.log(formated);
You can use Intl.NumberFormat object enables language-sensitive number formatting in a new project enviroment.
const money = 123456789.987654321;
const config = { style: 'currency', currency: 'VND', maximumFractionDigits: 9}
const formated = new Intl.NumberFormat('vi-VN', config).format(money);
console.log(formated);