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

bn library bugs when you're using units / precision zero #3227

Closed
LuizAsFight opened this issue Sep 29, 2024 · 1 comment · Fixed by #3300
Closed

bn library bugs when you're using units / precision zero #3227

LuizAsFight opened this issue Sep 29, 2024 · 1 comment · Fixed by #3300
Assignees
Labels
bug Issue is a bug

Comments

@LuizAsFight
Copy link
Contributor

fuels-ts SDK Version

latest

Toolchain Versions

not relevant

Node.js Version

No response

Browser

No response

Operating System

No response

Describe the Problem

when you call format({ units: 0, precision: 0 }) it will not return the correct value

the same happens on parseUnits function

Code Snippet

the workaround we've been doing on FE side is:


bn(amount).mul(10).format({ units: 1, precision: 0 });

which is basically multiplying by 10 first, then converting to units 1, which at the end of the day will be the same of passing units: 0

this is very overwhelming to do as we have many projects and some places can be forgotten, leading to number bugs.



### Contract ABI

_No response_

### Errors

_No response_
@maschad maschad added the bug Issue is a bug label Sep 30, 2024
@maschad maschad self-assigned this Sep 30, 2024
@maschad
Copy link
Member

maschad commented Oct 1, 2024

Thanks for opening this @LuizAsFight just so that we are on the same page, could you share a few examples of expected results. Such as:

 expect(bn('1000000000').format({ units: 0, precision: 0 })).toEqual('1,000,000,000');
 expect(bn('1000000000').format({ units: 0, precision: 2 })).toEqual('1,000,000,000.00');
    bn('1000000000').format({
       minPrecision: 2,
     })
   ).toEqual('1,000,000,000.00');
      bn('1000000000').format({
       minPrecision: 2,
       units: 8,
     })
   ).toEqual('10.00');

This will just help us to have a clear consensus around the desired output.

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

Successfully merging a pull request may close this issue.

2 participants