Skip to content
This repository has been archived by the owner on Feb 9, 2024. It is now read-only.

Create helper functions for formatting Big Numbers in BN.js #29

Open
DoubleOTheven opened this issue Mar 30, 2023 · 0 comments
Open

Create helper functions for formatting Big Numbers in BN.js #29

DoubleOTheven opened this issue Mar 30, 2023 · 0 comments

Comments

@DoubleOTheven
Copy link
Contributor

DoubleOTheven commented Mar 30, 2023

Feature Request

  • Create helper functions that take a BN.js, string, or number as a NUMBER input and format it in human readable ways. Each api registry has chain decimal information, which should be used to properly format decimals, etc.

Suggestion

useBalance()?.freeBalance will return something like 1096562700458522 for Contracts on Rococo.

  • We should be able to easily display that as 1,196.56 ROC, 1196.5627, 1096.562700458522, etc. We can control how many significant numbers are shown, show the currency, use commas, etc.
  • Add helpers for decimal math without floating point numbers. e.g. Chain A uses 12 decimals and Chain B uses 18 decimals. If we want to calculate an exchange rate between the two we want to do this easily.

Motivation

Formatting BN is tedious, and very common.

Use Cases

Displaying a user's balance with only two decimals. e.g. 1,096.56 ROC

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

Successfully merging a pull request may close this issue.

1 participant