function formatToCurrency(amount){
return (amount).toFixed(2).replace(/d(?=(d{3})+.)/g, '$&,');
}
formatToCurrency(12.34546); //"12.35"
formatToCurrency(42345255.356); //"42,345,255.36"
const formatter = new Intl.NumberFormat('en-US', {
style: 'currency',
currency: 'USD',
minimumFractionDigits: 2
})
formatter.format(1000) // "$1,000.00"
formatter.format(10) // "$10.00"
formatter.format(123233000) // "$123,233,000.00"
const rupiah = (number) => {
return new Intl.NumberFormat("id-ID", {
style: "currency",
currency: "IDR"
}).format(number);
}
const formatter = new Intl.NumberFormat('en-ID', {
style: 'currency',
currency: 'IDR'
}).format(10000000)
.replace(/[IDR]/gi, '')
.replace(/(.+d{2})/, '')
.trimLeft()
console.log(`Rp ${formatter}`)
(1234567.8).toFixed(2).replace(/(d)(?=(d{2})+d.)/g, '$1,') // "12,34,567.80"
const yourNumber = -100
const nf = new Intl.NumberFormat('en-GB', { style: 'currency', currency: 'GBP' })
console.log(nf.format(yourNumber))
Run code snippet