Skip to content
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

Losing fractional amount accuracy when sending large amount #133

Open
sunnyking opened this issue Oct 30, 2018 · 2 comments
Open

Losing fractional amount accuracy when sending large amount #133

sunnyking opened this issue Oct 30, 2018 · 2 comments
Assignees

Comments

@sunnyking
Copy link
Contributor

When sending a payment transaction 1,000,000,000.00000001 coins from a cold wallet address, the confirmation dialog loses the fractional 0.00000001 in the payment amount.

@zhangdong0620
Copy link
Contributor

In fact, whether using a cold wallet or a hot wallet, send or lease, there will be such a problem.

@0x100cc
Copy link
Contributor

0x100cc commented Nov 12, 2018

Sergiojiu747 and I found out the reason for the display problem.
The following is the original code:
amount: Number((this.coldAmount * VEE_PRECISION).toFixed(0)) where VEE_PRECISION=1e8
this is used to solve the problem of precision in arithmetic operation in JavaScript (By converting decimals to integers ,then calculating)
However, the maximum number of digits that javascript supports is 16bits.So if the integer >1e16 (or 9007199254740992),the result will be wrong.
Test results:
1.Input:10000000.00000001 位数:16 (Input1e8).toFixed(0): 1000000000000001 and transfered number is: 10000000.00000001
2.Input:1000000000.00000001 位数:18 (Input
1e8).toFixed(0): 100000000000000000 and transfered number is: 1000000000

So, the problem is caused by JavaScript itself.
One suggestion is that we can give a warning message if the amount is bigger than 16 digits , and suggest divide the transaction into small ones . Another suggestion is limiting the maximum transaction amount in the first place.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants