Chartjs-How to change number to $ with commas? Chart.js

4👍

You could use the format method of JS like this:

const amount = 10000;
const options2 = { style: 'currency', currency: 'USD' };
const numberFormat2 = new Intl.NumberFormat('en-US', options2);

console.log(numberFormat2.format(amount));
// expected output: "$10,000"

Here are docs about this

Here my guide to update, you only declare 2 variable in global

const options2 = { style: 'currency', currency: 'USD', minimumFractionDigits: 0 };
const numberFormat2 = new Intl.NumberFormat('en-US', options2);

And replace `return ‘$’ + value by this:

return numberFormat2.format(value.toFixed(0).replace(/\.0+$/, ""));

Leave a comment