最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - VND Currency formatting - Stack Overflow

programmeradmin1浏览0评论

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
Add a comment  | 

4 Answers 4

Reset to default 6

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));

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);
发布评论

评论列表(0)

  1. 暂无评论