Run details:
Mozilla/5.0 (Linux; Android 10) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/107.0.5304.141 Mobile DuckDuckGo/5 Safari/537.36
Chrome Mobile 107
Android
Mobile
one year ago
Test name Executions per second
toFixed(4) someFloat.toFixed(4); someFloat.t 1273363.0 Ops/sec
toPrecision(4).toString() 1334799.0 Ops/sec
(Math.round(*10000)/10000).toString() 1253635.0 Ops/sec
Math.floor fast 3892704.0 Ops/sec
Math.trunc 1268507.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