Skip to content

greaterThan

Check whether the value of a Dinero object is greater than another.

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

Parameters

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

Code examples

Compare two objects

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

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

greaterThan(d1, d2); // false

Compare two objects after normalization

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

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

greaterThan(d1, d2); // true

Released under the MIT License.