Normalize a set of Dinero objects to the highest scale of the set.
Normalizing to a higher scale means that the internal amount
value increases by orders of magnitude. If you're using the default Dinero.js implementation (with the number
calculator), be careful not to exceed the minimum and maximum safe integers.
Copy linkParameters
Name | Type | Description | Required |
---|---|---|---|
dineroObjects | Dinero<TAmount>[] | The Dinero objects to normalize. | Yes |
Copy linkCode examples
Copy linkNormalize objects to the same scale
import { dinero, normalizeScale } from 'dinero.js';
import { USD } from '@dinero.js/currencies';
const d1 = dinero({ amount: 100, currency: USD, scale: 2 });
const d2 = dinero({ amount: 2000, currency: USD, scale: 3 });
const [one, two] = normalizeScale([d1, d2]);
one; // a Dinero object with amount 1000 and scale 3
two; // a Dinero object with amount 2000 and scale 3