Re:Dinero.js – JavaScript library for working with monetary ...
by sgarman on Monday April 16, 2018 @05:10PM
(#16852812)
Do you have any suggestions on how to deal with money where you need more precision then cents? For example financials and inventory markets?
[ Parent
| on HN ]
Re:Dinero.js – JavaScript library for working with monetary ...
by pokoleo on Monday April 16, 2018 @05:17PM
(#16852870)
If you can find an atomic amount, (e.g. PicoDollars) I'd suggest using that. Javascript doesn't have an infinite precision integer type.
In cases where that isn't possible, try an infinite precision javascript library. https://github.com/MikeMcl/big.js
You could _probably_ find a way to shim big.js into OP's library :)
Re:Dinero.js – JavaScript library for working with monetary ...
by Vindicis on Tuesday April 17, 2018 @10:20AM
(#16858530)
Basically, you store everything as integers.You can specify whatever precision you want, just by saying x digits are before the decimal. E.g. 1.234566 is 1234566. Rounding when needed(just be consistent), but you never round until the last step which is when you're going to be displaying/storing the final value.