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

Utilities.formatToPrecision has wrong output for scientific notation #778

Open
JeneaVranceanu opened this issue Feb 13, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@JeneaVranceanu
Copy link
Collaborator

What happened?

Calling Utilities.formatToPrecision(..., fallbackToScientific: true) outputs a wrong value for some inputs.

Screenshot 2023-02-13 at 11 54 37

What are the steps to reproduce?

let balance = BigInt("100000000000000000000")
let formatted = Utilities.formatToPrecision(balance, units: .ether, decimalSeparator: ",", fallbackToScientific: true)

What is the expected behavior?

Value in formatted from the example above should be 1e20 but it's 0e-18 instead.

What is the error thrown?

What's the stack trace said?

OS version

Library version

3.1.1

@JeneaVranceanu JeneaVranceanu added the bug Something isn't working label Feb 13, 2023
@JeneaVranceanu
Copy link
Collaborator Author

To resolve that I suggest the following:

  • separate formatToPrecision into formatToPrecision and formatToScientificNotation;
  • formatToScientificNotation must have a flag useNormalNotation. Normal notation in a scientific number means we have 1 digit that is between in range [1,9] that is to the left side of the separator.
  • setting useNormalNotation to false will consider the formattingDecimals value that we have now. useNormalNotation set to true will ignore formattingDecimals.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant