1const formatToCurrency = amount => {
2 return "$" + amount.toFixed(2).replace(/\d(?=(\d{3})+\.)/g, "$&,");
3};
4formatToCurrency(12.34546); //"$12.35"
5formatToCurrency(42345255.356); //"$42,345,255.36
1function formatToCurrency(amount){
2 return (amount).toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,');
3}
4formatToCurrency(12.34546); //"12.35"
5formatToCurrency(42345255.356); //"42,345,255.36"
1const formatter = new Intl.NumberFormat('en-US', {
2 style: 'currency',
3 currency: 'USD',
4 minimumFractionDigits: 2
5})
6
7formatter.format(1000) // "$1,000.00"
8formatter.format(10) // "$10.00"
9
10
11-----------------------------------------------------
12const formatter = new Intl.NumberFormat('vi-VN', {
13 style: 'currency',
14 currency: 'VND',
15 minimumFractionDigits: 0
16})
17
18
19$('.total-price').html(formatter.format(price)); // 25.000đ
20