ThiepLV
ThiepLV

Reputation: 1279

VND Currency formatting

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.

Upvotes: 9

Views: 55248

Answers (4)

Nak
Nak

Reputation: 461

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

Upvotes: 0

You can use format from other country as below:

var x = 1000;
x = x.toLocaleString('it-IT', {style : 'currency', currency : 'VND'});
console.log(x);

Upvotes: 6

MinIsNghia
MinIsNghia

Reputation: 64

You can use Intl.NumberFormat See more

console.log(new Intl.NumberFormat('vi-VN', { style: 'currency', currency: 'VND' }).format(1000));

Upvotes: 2

DinosAur
DinosAur

Reputation: 1

var x = 1000;
x = x.toLocaleString('en-US', {style : 'currency', currency : 'VND'});
console.log(x);

Upvotes: 0

Related Questions