Formatting in percent by Intl.NumberFormat in JavaScript

Because 25.1 is 2510%. Percentages are fractions of 100. If you had 100% it would be 100/100 which is equal to 1. So 25.1% is 25/100 or 0.251 not 25.1

var discount = 0.251;

var option = {
  style: 'percent',
  minimumFractionDigits: 2,
  maximumFractionDigits: 2
};

var formatter = new Intl.NumberFormat("en-US", option);
var discountFormat = formatter.format(discount);

console.log(discountFormat);

Also if you wanted to keep the trailing zero you would need to set minimumFractionDigits as the default for percentages is 0.

If your value is the actual percentage to be displayed, you would just put the % symbol on the end, eg value = 25.1+"0%";.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)