-
Notifications
You must be signed in to change notification settings - Fork 7
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
dnum.from Incorrect number from String() converting to scientific notation #3
Comments
got here because that's how the pyth api is setup btw https://docs.pyth.network/pythnet-price-feeds/best-practices |
Oh good catch! Yes we should definitely handle this better. I’ve been doing some tests and noticed that even (10 ** 20).toFixed(20) // "100000000000000000000.00000000000000000000"
(10 ** 21).toFixed(20) // "1e+21" From Number.toFixed:
I see two paths:
Also I am thinking that it might be good to add some warning in the README about the limitations of using numbers as an input, compared to strings / bigints / dnums. What do you think? |
I think |
looks like from-exponential loses precision 😢 |
Oh too bad, yes then I guess the simplest way to handle it would be a custom error for now. Let me know if you want to open a PR for it, otherwise I’ll do it later this week :) |
Fixed 680f4ad |
@greg-schrammel I changed my mind and decided to use from-exponential rather than throwing an error. The reasoning is that |
in the
from
methodString(value)
converts expoents greater than 21 or less than -6 to scientific notation, which makes it not pass the regex in the next lineI was trying something like
multiply(price, 10 ** -8, 18)
It's not a big issue since
divide(price, 10 ** Math.abs(expo), 18)
should do the samea possible solution could be something like this, I'm not sure of the implications or if this should be handled in the lib, if you want I can look further and open a pr
It took some time today to figure what I was doing wrong here haha
Number.toString
The text was updated successfully, but these errors were encountered: