JavaScript Math.sumPrecise() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Method

Definition

Math.sumPrecise(numbers) adds all numbers in an iterable (like an array) and gives a more exact answer than adding them one by one with +. It avoids small rounding errors that pile up in the middle of a sum.

Read the syntax below, then try the three examples to see the method in action.

Syntax

Call the method on Math. Start with this line.

JavaScript
Math.sumPrecise(numbers)
CallWhat it does
Math.sumPrecise(numbers)Returns the precise sum of all numbers in the iterable.

Built into JavaScript. Call Math.sumPrecise(...) on the Math object — no import required. Math is not a constructor, so never write new Math().

Library declarations
JavaScript
Math.sumPrecise(numbers)

Parameters

ParameterDescription
numbersRequired. An iterable of numbers, such as an array. Every item must be a number.

Return Value

Return ValueDescription
NumberThe sum of all numbers. An empty iterable returns -0.

JavaScript Examples

Example 1 — Add Numbers in an Array

Pass an array and get the total. The result looks just like a normal sum for easy numbers.

JavaScript
console.log(Math.sumPrecise([1, 2, 3])); // 6
console.log(Math.sumPrecise([0.5, 0.25])); // 0.75
console.log(Math.sumPrecise([])); // -0
Try It Yourself

How It Works

  1. Simple sum. 1 + 2 + 3 is 6.
  2. Decimals. 0.5 + 0.25 is 0.75.
  3. Empty list. An empty array returns -0. It acts like 0 in most code.
  4. Only numbers. Every item must be a real number, not text.

Example 2 — Compare with Normal Addition

The famous problem: adding 0.1, 0.2 and 0.3 with + is slightly off.

JavaScript
const numbers = [0.1, 0.2, 0.3];
const naive = numbers.reduce(function (sum, n) {
  return sum + n;
}, 0);

console.log(naive); // 0.6000000000000001
console.log(Math.sumPrecise(numbers)); // 0.6
Try It Yourself

How It Works

  1. Loop add. reduce adds one number at a time. Each step can lose a tiny bit of accuracy.
  2. Small error. The normal result is 0.6000000000000001.
  3. One exact sum. Math.sumPrecise keeps the exact total and rounds only once at the end.
  4. Better answer. The result is the clean 0.6.

Example 3 — Big Numbers and Feature Detection

Large numbers can wipe out small ones. Also check that the method exists before calling it.

JavaScript
const values = [1e20, 0.1, -1e20];
console.log(values[0] + values[1] + values[2]); // 0

if (typeof Math.sumPrecise === "function") {
  console.log(Math.sumPrecise(values));
} else {
  console.log("Math.sumPrecise is not supported here");
}
Try It Yourself

How It Works

  1. Huge plus tiny. 1e20 + 0.1 loses the 0.1 because the big number is too large to hold it.
  2. Wrong answer. After -1e20 the normal sum is 0.
  3. Safe check. typeof Math.sumPrecise === "function" avoids errors in old browsers.
  4. Precise answer. In a browser with support, Math.sumPrecise returns the correct 0.1.

Browser & Runtime Support

Math.sumPrecise() is a newer method. It became Baseline newly available in April 2026: Chrome and Edge 147, Firefox 137, and Safari 26.2 or later. Older browsers do not have it.

✓ Baseline · Newly available

Math.sumPrecise()

Works in current versions of the major browsers, but not in older ones. Check support before you depend on it.

82% Approx. global usage
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full support
Math.sumPrecise Newer feature

Bottom line: Test with typeof Math.sumPrecise === "function" and fall back to reduce() in older browsers and older Node.js versions.

Frequently Asked Questions

It adds all numbers in an iterable, like an array, and returns a sum with fewer floating point rounding errors than adding in a loop.
Normal addition rounds after every step. Math.sumPrecise keeps the exact total and rounds only once at the end.
It returns -0 for an empty iterable. In most code -0 behaves like 0.
No. Every item must be a number. If an item is a string, JavaScript throws a TypeError.
It is new. Chrome and Edge 147, Firefox 137 and Safari 26.2 or later support it. Older browsers, and many older Node.js versions, do not.
Use reduce() with +, or a small helper library for exact sums. You can also check typeof Math.sumPrecise === "function" and fall back to reduce().

Next: tan()

Learn how to tangent of an angle in radians.

tan() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

9 people found this page helpful