Math.sumPrecise()
Math.sumPrecise() computes sums with reduced floating-point error compared with naive repeated addition. It is useful when numeric precision matters across many values.
Overview
Math.sumPrecise() computes sums with reduced floating-point error compared with naive repeated addition. It is useful when numeric precision matters across many values.
Browser support
| Feature | Desktop | Mobile | ||||
|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Safari | Chrome Android | Safari iOS | |
| 147 | 147 | 137 | 26.2 | 147 | 26.2 | |
Syntax
// Standard addition results in rounding errors
0.1 + 0.2 + 0.3; // 0.6000000000000001
// Precise sum
Math.sumPrecise([0.1, 0.2, 0.3]); // 0.6 Live demo
Compare normal addition and sumPrecise
Check whether Math.sumPrecise improves floating-point summation in the current runtime.
Sum many fractional values
Test repeated decimal values where floating-point error tends to accumulate.
Use a fallback helper
Build a small helper that prefers Math.sumPrecise when present.
Use cases
Financial-style totals
Reduce rounding drift when summing many decimal values for reporting or reconciliation.
Numeric aggregation
Use more stable summation in charting, measurement, or simulation results.
Cautions
- Improved summation helps, but it does not remove every precision concern in floating-point workflows.
- Keep the numeric model explicit if the domain requires exact decimal semantics.
Accessibility
- More accurate totals support trustworthy user-facing summaries and announcements.
- If numbers drive status messages or billing UI, precision improvements can reduce confusing discrepancies.
Related links
Powered by web-features