Fix bug where two decimal numbers added give wrong output #14
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
I have added a fix for bug where two decimal numbers when added gives wrong output
Motivation and Context
In the code when comparing the totalSupply of token and addition of all partitions of token is done, it wasn't matching because the addition was done in Type "Numbers", to fix we have added a function which first coverts them into BigNumber and then add.
For example -
const num1 = 11031862.87;
const num2 = 2.03;
(current scenario)
const result1 = num1 + num2;
console.log(result1); // Output: 11031864.899999999
(fixed scenario)
const bigNum1 = new BigNumber(num1);
const bigNum2 = new BigNumber(num2);
const result2 = bigNum1.plus(bigNum2);
console.log(result2.toString()); // Output: 11031864.9
How Has This Been Tested?
Tested in local environment and nodeJs playgorud - https://codesandbox.io/s/bignumber-js-forked-u4qny6
Screenshots (if appropriate):
Types of changes
Checklist: