toFixed(4) vs toPrecision(4).toString() vs (Math.round(*10000)/10000)Fastest: (Math.round(*10000)/10000) (24.7x faster)
153,299,024 ops/sec
8,317,891 ops/sec
6,205,516 ops/sec
Results show median performance across all community submissions. Run this benchmark yourself to verify on your device.
| Test case name | Result |
|---|---|
| toFixed(4) | |
| toPrecision(4).toString() | |
| (Math.round(*10000)/10000) |
| Test name | Executions per second |
|---|---|
| ✓ (Math.round(*10000)/10000) | 476,872,352 Ops/sec |
| toPrecision(4).toString() | 6,367,108 Ops/sec |
| toFixed(4) | 3,899,066 Ops/sec |