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 1273362.6 Ops/sec
toPrecision(4).toString() 1334798.8 Ops/sec
(Math.round(*10000)/10000).toString() 1253635.2 Ops/sec
Math.floor fast 3892703.5 Ops/sec
Math.trunc 1268506.6 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


;