Transform a Dinero object to a new scale.
Transforming 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.
info
When transforming to smaller scales, transformScale
truncates the amount.
Copy linkParameters
Name | Type | Description | Required |
---|---|---|---|
dineroObject | Dinero<TAmount> | The Dinero object to transform. | Yes |
newScale | TAmount | The new scale. | Yes |
Copy linkCode examples
Copy linkTransform an object to a new scale
import { dinero, transformScale } from 'dinero.js';
import { USD } from '@dinero.js/currencies';
const d = dinero({ amount: 500, currency: USD, scale: 2 });
transformScale(d, 4); // a Dinero object with amount 50000 and scale 4