Run details:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36
Chrome 135
Windows
Desktop
one year ago
Math.trunc
219.9M/s
(Math.round(*10000)/10000).toString()
219.4M/s
Math.floor fast
212.3M/s
toPrecision(4).toString()
20.4M/s
toFixed(4) someFloat.toFixed(4); someFloat.t
20.3M/s
View exact numbers
Test name Executions per second
Math.trunc 219,873,680 Ops/sec
(Math.round(*10000)/10000).toString() 219,405,376 Ops/sec
Math.floor fast 212,288,720 Ops/sec
toPrecision(4).toString() 20,381,592 Ops/sec
toFixed(4) someFloat.toFixed(4); someFloat.t 20,311,694 Ops/sec
Script Preparation code:
Tests: