Tests:
  • Intl

    AخA
     
    new Intl.NumberFormat('en-US', {
        style: 'decimal',
        useGrouping: true,
        minimumFractionDigits: 0,
        maximumFractionDigits: 3,
      }).format('100000.234')
  • String

    x
     
    const value = '100000.234';
    function decimalFormat(value) {
      // fix for rounding issues, see Mozilla docs on method toFixed()
      const normalizedValue = value * 10 ** 3;
      const formattedValue = normalizedValue.toFixed(0);
      return +formattedValue / 10 ** 3;
    }
    function formatThousandsSeparator(value) {
      // TODO: consider replacing this later with  Intl.NumberFormat
      const parts = value.toString().split('.');
      parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ',');
      return parts.join('.');
    }
    decimalFormat(formatThousandsSeparator(value))
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    Intl
    String

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 3 years ago)
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36
Chrome 97 on Mac OS X 10.15.7
View result in a separate tab
Test name Executions per second
Intl 29760.8 Ops/sec
String 2020179.9 Ops/sec