3 ms·
For client-side and server-side JS, we use big.js [1]. - We use strict mode [2] so we are forced to only input strings and never numbers. - We set rounding mo
by joshxyz 5y ago
For client-side and server-side JS, we use big.js [1].
- We use strict mode [2] so we are forced to only input strings and never numbers.
- We set rounding mode [3] to round-down.
- Finally the default 20 decimal places [4] seems reliable enough for most of our use-cases.
- It's also immutable and we can easily truncate decimal places with toFixed(dp) [5]
[1] https://github.com/MikeMcl/big.js/ https://github.com/MikeMcl/big.js/
[2] http://mikemcl.github.io/big.js/#strict http://mikemcl.github.io/big.js/#strict
[3] http://mikemcl.github.io/big.js/#rm http://mikemcl.github.io/big.js/#rm
[4] http://mikemcl.github.io/big.js/#dp http://mikemcl.github.io/big.js/#dp
[5] http://mikemcl.github.io/big.js/#toF http://mikemcl.github.io/big.js/#toF