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

equal

boolean

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.

Copy linkParameters

NameTypeDescriptionRequired
dineroObjectDinero<TAmount>

The first Dinero object to compare.

Yes
comparatorDinero<TAmount>

The second Dinero object to compare.

Yes

Copy linkCode examples

Copy linkCompare two identical objects

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

Copy linkCompare two objects with different amounts

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

Copy linkCompare two identical objects after normalization

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

Copy linkCompare two objects with different currencies

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