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

haveSameAmount

boolean

Check whether a set of Dinero objects have the same amount.

Copy linkParameters

NameTypeDescriptionRequired
dineroObjectsDinero<TAmount>[]

The Dinero object to check.

Yes

Copy linkCode examples

Copy linkCompare two objects with the same amount

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

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

haveSameAmount([d1, d2]); // true

Copy linkCompare two objects with different amount

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

const d1 = dinero({ amount: 1000, currency: USD });
const d2 = dinero({ amount: 2000, currency: USD });

haveSameAmount([d1, d2]); // false

Copy linkCompare two objects with the same amount once normalized

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

const d1 = dinero({ amount: 1000, currency: USD });
const d2 = dinero({ amount: 10000, currency: USD, scale: 3 });

haveSameAmount([d1, d2]); // true