Skip to content

Working with BigNumber and different decimals #2015

Answered by ricmoo
austinbv asked this question in Q&A
Discussion options

You must be logged in to vote

If you only care about the truncate whole value, the math should work fine, balance.mul(price).div(ethers.constants.WeiPerEther). The order is important. Are you sure you want to divide though? If you do unit analysis, are you targeting your price in ether or in wei?

You can also use the ethers.FixedNumber class to work things through and see where the fractional bits are.

Replies: 2 comments 5 replies

Comment options

You must be logged in to vote
4 replies
@austinbv
Comment options

@zemse
Comment options

zemse Sep 7, 2021
Collaborator

@austinbv
Comment options

@zemse
Comment options

zemse Sep 9, 2021
Collaborator

Answer selected by austinbv
Comment options

You must be logged in to vote
1 reply
@austinbv
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants