Compatibility of Number.prototype.toLocaleString

Number.prototype.toLocaleString is used in amount formatting, but compatibility problems occur in some older browsers

var a = 10000000;
a.toLocaleString(); 
// chrome 68 "10,000,000" 
//  7.5.5 "10,000,000.000"

Sogou 7.5.5 is over .000
the original formatting function (formats the thousandth and retains two decimal places)

formatAmount: function (amount) { // 
  if (typeof amount === "undefined" || amount === "") return "";
  if (amount - 0 === 0) return "0.00";
  let num = amount - 0;
  let str = (num-0).toFixed(2); // 
  let num_int = str.split(".")[0];
  let num_point = str.split(".")[1];
  return `${(num_int-0).toLocaleString()}.${num_point}`;
}

after compatibility

formatAmount: function (amount) { // 
      if (typeof amount === "undefined" || amount === "") return "";
      if (amount - 0 === 0) return "0.00";
      let num = amount - 0;
      let str = (num-0).toFixed(2); // 
      let num_int = (str.split(".")[0] - 0).toLocaleString();
      let num_point = str.split(".")[1];
      return `${num_int.indexOf(".")>-1?num_int.split(".")[0]:num_int}.${num_point}`;
    }
The kernel version of

Sogou 7.5.5 is Chromium 49.0.2623
according to MDN shows that this method is supported. So how to judge this compatibility? Methods can be used, but the results returned are different.


.toLocaleString(undefined,{minimumFractionDigits:0,maximumFractionDigits:0})
Menu