Skip to content

equal ​

Check whether the value of a Dinero object is equal to another.

This function does same-value equality, determining whether two Dinero objects are functionally equivalent. It also normalizes objects to the same scale (the highest) before comparing them.

Parameters ​

NameTypeDescriptionRequired
dineroObjectDinero<TAmount, TCurrency>The first Dinero object to compare.Yes
comparatorDinero<TAmount, TCurrency>The second Dinero object to compare.Yes

Code examples ​

Compare two identical objects ​

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

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

equal(d1, d2); // true

Compare two objects with different amounts ​

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

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

equal(d1, d2); // false

Compare two identical objects after normalization ​

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

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

equal(d1, d2); // true

Compare two objects with different currencies ​

js
import { dinero, equal } from 'dinero.js';
import { USD, EUR } from 'dinero.js/currencies';

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

equal(d1, d2); // false

Released under the MIT License.