3 ms·
Dinero stores three pieces of data with a dynamic scale: https://v2.dinerojs.com/docs/core-concepts/scale https://v2.dinerojs.com/docs/core-concepts/scale - am
by Leftium 4y ago
Dinero stores three pieces of data with a dynamic scale: https://v2.dinerojs.com/docs/core-concepts/scale https://v2.dinerojs.com/docs/core-concepts/scale
- amount: expressed in the smallest subdivision of the currency, as an integer.
- currency: unique code, base, and exponent
- scale: the scale is essential to accurately represent monetary values without losing precision. It automatically adapts as needed to ensure you always retain accurate amounts.
---
Multiply[1]: If you need to multiply by a fractional multiplier, you shouldn't use floats, but scaled amounts instead. For example, instead of passing 2.1, you should pass { amount: 21, scale: 1 }. When using scaled amounts, the function converts the returned objects to the safest scale.
Allocate[2] (alternative to dividing): Distribute the amount of a Dinero object across a list of ratios.
[1]: https://v2.dinerojs.com/docs/api/mutations/multiply https://v2.dinerojs.com/docs/api/mutations/multiply
[2]: https://v2.dinerojs.com/docs/api/mutations/allocate https://v2.dinerojs.com/docs/api/mutations/allocate