javascript format currency
function formatToCurrency(amount){
return (amount).toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,');
}
formatToCurrency(12.34546); //"12.35"
formatToCurrency(42345255.356); //"42,345,255.36"
javascript format currency
function formatToCurrency(amount){
return (amount).toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,');
}
formatToCurrency(12.34546); //"12.35"
formatToCurrency(42345255.356); //"42,345,255.36"
how to format money as currency string
(12345.67).toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,'); // 12,345.67
format currency javascript
const formatter = new Intl.NumberFormat('en-US', {
style: 'currency',
currency: 'USD',
minimumFractionDigits: 2
})
formatter.format(1000) // "$1,000.00"
formatter.format(10) // "$10.00"
-----------------------------------------------------
const formatter = new Intl.NumberFormat('vi-VN', {
style: 'currency',
currency: 'VND',
minimumFractionDigits: 0
})
$('.total-price').html(formatter.format(price)); // 25.000đ
js format urcurency
// Create our number formatter.
var formatter = new Intl.NumberFormat('en-US', {
style: 'currency',
currency: 'USD',
});
formatter.format(2500); /* $2,500.00 */
float to currency js
function floatToEuro(float){
var euroCurrency
euroCurrency = '\u20AC' + float.toLocaleString('nl-NL',{minimumFractionDigits: 2});
console.log(euroCurrency);
return euroCurrency;
};
format money js
/* npm install format-money-js */
const { FormatMoney } = require('format-money-js');
const fm = new FormatMoney({
decimals: 2
});
console.log(fm.from(
12345.67,
{ symbol: '$' },
true // Parse, return object
)
);
/* return object:
{
source: 12345.67,
negative: false,
fullAmount: '12,345.67',
amount: '12,345',
decimals: '.67',
symbol: '$'
}*/
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us