Add number formatting utilities
See original GitHub issueFrom an offline discussion:
formatNumber()
: useIntl.formatNumber()
formatTokenAmount()
: build on top offormatNumber()
and add some options to make it easier to format token amounts (e.g. see this function)
Issue Analytics
- State:
- Created 4 years ago
- Comments:10 (10 by maintainers)
Top Results From Across the Web
Create a custom number format - Microsoft Support
Create and build a custom numeric format to show your numbers as percentages, currency, dates, and more. ... Add a space to separate...
Read more >Number formatting utility for Node and Browser - GitHub
Format ; options.round, Number|Falsy, Precision (e.g. 0.001 for 3 decimal places or 1000 for rounding to thousands, use 1 to round to whole...
Read more >Create a custom cell format in Numbers on Mac - Apple Support
In the Format sidebar, click the Cell tab. Click the Data Format pop-up menu, then choose Create Custom Format. Type a name for...
Read more >Custom Excel number format - Ablebits
Select a cell for which you want to create custom formatting, and press Ctrl+1 to open the Format Cells dialog. Under Category, select...
Read more >How To Enforce Form Field Number Formatting - YouTube
How To Enforce Form Field Number Formatting - Insert Help Text ... tool form fields, you can enforce certain number formatting to keep...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@ECWireless I think we could adapt them to make it a bit simpler to use:
pow
,multiplier
anddecimals
I think we could replace these three params by a single
decimals = 18
, since it is both defined by ERC-20 and widely used. Similarly toamount
, this should be either a number, or any object with atoNumber()
method (i.e. we should callNumber()
on it).amount
This should be either a string, a
BigInt
instance, or any object with a .toString() method (i.e. we should callString()
on it).rounding
I think we could rename this to something like
displayDecimals
,roundToDecimals
,decimalPlaces
, or justprecision
?isIncoming
I don’t think this is needed, we can use a sign on the BigInt +
displaySign
(orsignDisplay
) to determine that.displaySign
We might want to name it
signDisplay
to align it with the newIntl.NumberFormat
API.@sohkai @ECWireless what would you guys think about naming the function
formatAmount()
? It might sound a bit generic, but I think there is enough context for authors to know what it is about. It would also make it clearer that we can use it to format currencies like USD as well.Closed with #728