# Math.sumPrecise()

> The `Math.sumPrecise()` static JS method returns the sum of numbers from an iterable with improved precision.

## How do I sum floating point numbers precisely in JavaScript?

The static method that takes an iterable of numbers and returns their sum, avoiding the floating-point precision loss of sequential addition. For example, it returns '0.6' for '[0.1, 0.2, 0.3]' instead of an approximate value.

- Topic: Math
- Type: method
- Browser support: Chrome 147+, Chrome Android 147+, Edge 147+, Firefox 137+, Firefox Android 137+, Safari 26.2+, Safari iOS 26.2+

## Example

Wrong:

```js
const total = [0.1, 0.2, 0.3].reduce((a, b) => a + b, 0);
console.log(total); // 0.6000000000000001
```

Right:

```js
const total = Math.sumPrecise([0.1, 0.2, 0.3]);
console.log(total); // 0.6
```

`reduce()` rounds after every addition, while `Math.sumPrecise()` rounds only the final exact sum.

## Common mistakes

- Calling `Math.sumPrecise(a, b)` instead of `Math.sumPrecise([a, b])`.

## Key points

- `Math.sumPrecise()` receives an iterable like an array, not separate arguments.
- All values are numbers: strings and `BigInt` values are not passed, because they throw a `TypeError`.
- Money is still stored as integers in minor units, not summed as floats.

## Interview questions

### What does Math.sumPrecise() return for an empty array?

It returns `-0`, which equals 0 in comparisons.

### Does Math.sumPrecise() make 0.1 exact?

No. Each input is still a binary float. It only avoids extra rounding between additions, so the result is the closest float to their exact sum.

### Is Math.sumPrecise() slower than reduce()?

It does more work per value than a plain loop, so use it where accuracy matters, not in tight hot paths.

## Related cards

- [Number.EPSILON](https://wonderium.dev/js/number-epsilon.md)
- [Array.reduce()](https://wonderium.dev/js/array-reduce.md)
- [Iterator.reduce()](https://wonderium.dev/js/iterator-reduce.md)
- [number](https://wonderium.dev/js/number-type.md)

---

- Level: [JavaScript](https://wonderium.dev/js.md)
- HTML version: https://wonderium.dev/js/math-sum-precise
- Last updated: 2026-11-25
