RJR
Convex Community3y ago
10 replies
RJ

Arbitrary-precision decimals without `Math.random`

I needed to perform some arithmetic (safely)—specifically, I needed to convert a JS
number
representing dollars into a JS
number
representing cents. I tried using https://github.com/MikeMcl/bignumber.js for this in a mutation, but discovered that it imports
Math.random
. I ended up settling for https://github.com/MikeMcl/decimal.js-light, which is just a trimmed-down version of https://github.com/MikeMcl/decimal.js (yes, these are all written by the same person—and those aren't even all of the arbitrary-precision decimal libraries he maintains!), as it happens to not import
Math.random
, and still accomplishes all of what I need.

I guess this is either a question or an offering of advice—the question is: is anyone aware of another library I ought to have considered for this task (I can't imagine I'll be the only Convex user to have this requirement)? And the offering is: if anyone is looking for such a library, I can confirm that https://github.com/MikeMcl/decimal.js-light works!
Was this page helpful?