Run details:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36
Chrome 120
Windows
Desktop
one year ago
Test name Executions per second
toFixed(4) someFloat.toFixed(4); someFloat.t 3558038.2 Ops/sec
Math.pow - Math.round 3849543.8 Ops/sec
Script Preparation code:
AخA
 
var someFloat = 0.123456789;
Tests:
  • toFixed(4) someFloat.toFixed(4); someFloat.t

     
    +someFloat.toFixed(4);
  • Math.pow - Math.round

     
    var nb = Math.pow(10, 4);
    (Math.round(someFloat*nb)/nb);