Test name | Executions per second |
---|---|
myFloat.toFixed(2) | 1442765.0 Ops/sec |
myFloat.toPrecision(2) | 1664526.0 Ops/sec |
Math.round(myFloat*100)/100 i.e. 2 places | 1388430.2 Ops/sec |
Bitwise: signed round to 2 places | 1359184.5 Ops/sec |
Bitwise: UNsigned round to 2 places | 1999135.2 Ops/sec |
myFloat.toFixed(0) i.e. round to int | 1493618.0 Ops/sec |
Math.round(myFloat) | 1804318.8 Ops/sec |
Bitwise: signed round to nearest int | 3153633.2 Ops/sec |
Floor (round down only to int) | 1700823.5 Ops/sec |
Trunc (round towards zero) | 1646082.4 Ops/sec |
Bitwise: signed round to zero (trunc) | 3202424.2 Ops/sec |