Get to know MDN better
Since April 2026, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.
The Math.sumPrecise() static method takes an iterable of numbers and returns the sum of them. It is more precise than summing them up in a loop, because it avoids floating point precision loss in intermediate results.
An iterable (such as an Array) of numbers.
A number that is the sum of the numbers in the numbers iterable. If the iterable is empty, the return value is -0 (not 0).
If numbers is not an iterable, or if any of the numbers in the iterable is not of the number type.
Because sumPrecise() is a static method of Math, you always use it as Math.sumPrecise(), rather than as a method of a Math object you created (Math is not a constructor).
The method is called Math.sumPrecise() because it is more precise than naïvely summing up numbers in a loop. Consider the following example:
The output is 0. This is because 1e20 + 0.1 cannot be represented precisely in 64-bit floats, so the intermediate result is rounded to 1e20. Then, the sum of 1e20 and -1e20 is 0, so the final result is 0.
Math.sumPrecise() avoids this issue by using some specialized summing algorithm. It works as if the floating point numbers are summed up using their precise mathematical values, and the final result is then converted to the nearest representable 64-bit float. This still cannot avoid the 0.1 + 0.2 precision problem:
Because the floating point literals 0.1 and 0.2 already represent mathematical values greater than 0.1 and 0.2, and their sum's closest 64-bit float representation is actually 0.30000000000000004.
| ECMAScript® 2027 Language Specification # sec-math.sumprecise |
Enable JavaScript to view this browser compatibility table.
This page was last modified on Jul 10, 2025 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.