Run details:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36
Chrome 131
Windows
Desktop
one year ago
Math.floor fast
89.4M/s
(Math.round(*10000)/10000).toString()
64.8M/s
Math.trunc
57.8M/s
toPrecision(4).toString()
5.9M/s
toFixed(4) someFloat.toFixed(4); someFloat.t
4.5M/s
View exact numbers
Test name Executions per second
Math.floor fast 89,395,800 Ops/sec
(Math.round(*10000)/10000).toString() 64,772,380 Ops/sec
Math.trunc 57,775,008 Ops/sec
toPrecision(4).toString() 5,902,614 Ops/sec
toFixed(4) someFloat.toFixed(4); someFloat.t 4,483,818 Ops/sec
Script Preparation code:
Tests: