Skip to content

normalizeScale

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.

Parameters

NameTypeDescriptionRequired
dineroObjectsDinero<TAmount>[]The Dinero objects to normalize.Yes

Code examples

Normalize objects to the same scale

js
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

Released under the MIT License.