Test name | Executions per second |
---|---|
myFloat.toFixed(2) | 1149624.6 Ops/sec |
myFloat.toPrecision(2) | 1195929.5 Ops/sec |
Math.round(myFloat*100)/100 i.e. 2 places | 1014976.9 Ops/sec |
Bitwise: signed round to 2 places | 1330217.1 Ops/sec |
Bitwise: UNsigned round to 2 places | 1850317.1 Ops/sec |
myFloat.toFixed(0) i.e. round to int | 1218926.2 Ops/sec |
Math.round(myFloat) | 1012458.7 Ops/sec |
Bitwise: signed round to nearest int | 1904663.0 Ops/sec |
Floor (round down only to int) | 1013372.7 Ops/sec |
Trunc (round towards zero) | 1010681.6 Ops/sec |
Bitwise: signed round to zero (trunc) | 1795265.4 Ops/sec |