toFixed(4) vs toPrecision(4).toString() vs (Math.round(*10000)/10000).toString() vs ~~(someFloat * 10000) / 10000| Test case name | Result |
|---|---|
| toFixed(4) | |
| toPrecision(4).toString() | |
| (Math.round(*10000)/10000).toString() | |
| ~~(someFloat * 10000) / 10000 |
| Test name | Executions per second |
|---|---|
| ✓ ~~(someFloat * 10000) / 10000 | 12,792,228 Ops/sec |
| toPrecision(4).toString() | 4,563,444 Ops/sec |
| (Math.round(*10000)/10000).toString() | 4,327,884 Ops/sec |
| toFixed(4) | 3,565,014 Ops/sec |