parseFloat() + toFixed(4) vs parseFloat() + toPrecision(4) vs Math.round(*10000)/10000Fastest: Math.round(*10000)/10000 (15.8x faster)
105,461,568 ops/sec
8,453,128 ops/sec
6,655,225 ops/sec
Results show median performance across all community submissions. Run this benchmark yourself to verify on your device.
| Test case name | Result |
|---|---|
| parseFloat() + toFixed(4) | |
| parseFloat() + toPrecision(4) | |
| Math.round(*10000)/10000 |
| Test name | Executions per second |
|---|---|
| ✓ Math.round(*10000)/10000 | 1,504,486,144 Ops/sec |
| parseFloat() + toFixed(4) | 11,696,507 Ops/sec |
| parseFloat() + toPrecision(4) | 9,823,646 Ops/sec |