Click here for v1.x documentation.
Dinero.js
Dinero.js version

add

Dinero<TAmount>

Add up two Dinero objects.

You can only add objects that share the same currency. The function also normalizes objects to the same scale (the highest) before adding them up.

Copy linkParameters

NameTypeDescriptionRequired
augendDinero<TAmount>

The Dinero object to add to.

Yes
addendDinero<TAmount>

The Dinero object to add.

Yes

Copy linkCode examples

Copy linkAdd objects

import { dinero, add } from 'dinero.js';
import { USD } from '@dinero.js/currencies';

const d1 = dinero({ amount: 500, currency: USD });
const d2 = dinero({ amount: 100, currency: USD });

add(d1, d2); // a Dinero object with amount 600

Copy linkAdd objects with a different scale

import { dinero, add } from 'dinero.js';
import { USD } from '@dinero.js/currencies';

const d1 = dinero({ amount: 400, currency: USD });
const d2 = dinero({ amount: 104545, currency: USD, scale: 4 });

add(d1, d2); // a Dinero object with amount 144545 and scale 4

Copy linkAdd more than two objects

To retrieve the sum of multiple objects, you can call the add function multiple times.

import { dinero, add } from 'dinero.js';
import { USD } from '@dinero.js/currencies';

const d1 = dinero({ amount: 300, currency: USD });
const d2 = dinero({ amount: 200, currency: USD });
const d3 = dinero({ amount: 100, currency: USD });

const addMany = (addends) => addends.reduce(add);

addMany([d1, d2, d3]); // a Dinero object with amount 600