-
Notifications
You must be signed in to change notification settings - Fork 188
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: formatting big.js objects with scale larger than 21 fails #716
Comments
I tried to look through this one for you, but its hard to debug the issue without a |
@johnhooks |
I found it. I'll take another look. |
@bkiac you are 100% on the right track. The solution is to add your own formatter when you use formatter = {
toNumber: Number,
toString: String,
}, In PR #724 I'm currently doing this: dinero.js/test/utils/createBigjsDinero.ts Lines 6 to 23 in dff300e
I'm trying to track down why the |
Just realized this was a multipart question.
|
@bkiac I couldn't find any reason that the |
ty for taking a look at this, making |
Is there an existing issue for this?
Current behavior
I'm using big.js with dinero because I need it for cryptocurrencies and large USD values but after following the documentation to create a custom calculator I noticed that formatting breaks if the scale is too large (>= 22)
My first problem was that I receive arbitrary precision USD values from an API and I need to calculate the scale of these values. This is how I did it, but I feel I'm missing something and this has to be an overkill:
and when I receive a value that has precision 22 or larger,
toDecimal
function breaks and the output is in scientific notation with multiple decimal points:Expected behavior
I had to create a custom formatter to make it work:
Unless I'm doing something incredibly stupid with parsing the arbitrary precision, I think this should be added to the docs. I can open a PR if you can point me in the right direction.
And a quick question, why is the
amount
arg in the formatter functions optional?Steps to reproduce
https://replit.com/@bkiac/dinerowithbig#index.ts
Version
2.0.0-alpha.13
Environment
any
Code of Conduct
The text was updated successfully, but these errors were encountered: