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"