jup-ag / terminal

Jupiter Terminal is an open-sourced, lite version of Jupiter that provides end-to-end swap flow by linking it in your HTML.
https://terminal.jup.ag
70 stars 34 forks source link

Rounding issue with tiny numbers #72

Closed NotoriousPyro closed 1 week ago

NotoriousPyro commented 1 month ago

Image pretty much explains it, but when you have a very small amount of something and click MAX, it is rounding it to a much larger number... so 0.00000026 is being round to 2.67 which is out by roughly ~10⁷

image

worlddlckgh commented 1 week ago

https://github.com/jup-ag/terminal/pull/82 This PR should fix that

NotoriousPyro commented 3 days ago

Doesn't seem to be fixed... image

NotoriousPyro commented 3 days ago

As soon as toFixed is called (https://github.com/jup-ag/terminal/pull/82/files#diff-07efa3ad56d0dc57c345fd62ecdef9c8892a1bf5e798d7d2d29161c374d29ec9R38), the precision is lost... the only way to do it is use strings and BigNumbers/Decimal. The field would have to be changed to a string field... As soon as anything is parsed into a number in JS, it is turned into a floating point number and suffers the same fate. Alternatively, using bigint and converting to strings as needed...