Skip to content

Conversation

@NickSneo
Copy link

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

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Signed-off-by: Nischal Sharma <nischal@web3labs.com>
@NickSneo NickSneo requested a review from siibars as a code owner May 12, 2023 05:49
@github-actions
Copy link

github-actions bot commented May 12, 2023

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

@NickSneo
Copy link
Author

I have read the CLA Document and I hereby sign the CLA

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

Successfully merging this pull request may close these issues.

1 participant