Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VND Currency formatting

Tags:

javascript

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.

like image 993
ThiepLV Avatar asked Jun 23 '16 08:06

ThiepLV


People also ask

What is Intl NumberFormat?

The Intl.NumberFormat object enables language-sensitive number formatting.

How do you format numbers in JavaScript?

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.


2 Answers

You can use format from other country as below:

var x = 1000;
x = x.toLocaleString('it-IT', {style : 'currency', currency : 'VND'});
console.log(x);
like image 68
www.AdvancedCheckout.com Avatar answered Oct 12 '22 16:10

www.AdvancedCheckout.com


You can use Intl.NumberFormat See more

console.log(new Intl.NumberFormat('vi-VN', { style: 'currency', currency: 'VND' }).format(1000));
like image 32
MinIsNghia Avatar answered Oct 12 '22 16:10

MinIsNghia