Run details:
Mozilla/5.0 (Android 6.0.1; Mobile; rv:93.0) Gecko/93.0 Firefox/93.0
Firefox Mobile 93
Android 6.0.1
Mobile
3 years ago
Test name Executions per second
toFixed(4) someFloat.toFixed(4); someFloat.t 1276525.1 Ops/sec
toPrecision(4).toString() 1005592.6 Ops/sec
(Math.round(*10000)/10000).toString() 141019296.0 Ops/sec
Math.floor fast 141460336.0 Ops/sec
Math.trunc 140164864.0 Ops/sec
Script Preparation code:
Tests:
  • toFixed(4) someFloat.toFixed(4); someFloat.t

  • toPrecision(4).toString()

  • (Math.round(*10000)/10000).toString()

  • Math.floor fast

  • Math.trunc