Intl.NumberFormat can format percentages

The Intl.NumberFormat object can be used to format percentages.

const percentage = 0.12;

const enCaPercentageFormatter = Intl.NumberFormat('en-CA', {
  style: 'percent',
});
const frCaPercentageFormatter = Intl.NumberFormat('fr-CA', {
  style: 'percent',
});
const turkishPercentageFormatter = Intl.NumberFormat('tr', {
  style: 'percent',
});

enCaPercentageFormatter.format(percentage); // "12%"
frCaPercentageFormatter.format(percentage); // "12 %"
turkishPercentageFormatter.format(percentage); // "%12"
Latest Today I Learned Posts
HTML image decoding attribute Human readable relative date strings in standard JavaScript at() method in JavaScript Barcode Detection API