Skip to content

.toString vs toNumber confusion #2724

Answered by othaime-en
TimeKeyRoll asked this question in Q&A
Discussion options

You must be logged in to vote

Hey @TimeKeyRoll the difference with the way we use .toNumber() and .toString() is in the size of the number. In the case above, we used to .toString() on availableBorrowsETH because it was BigNumber (16500000000000000) that is waay above what javascript can handle . That's why we converted it to a string because .toNumber() wouldn't just work. On the other hand, daiPrice is a little smaller (735870000000000) that when converted to a number it doesn't overflow. It is slightly below the limit of how big a number can be in javascript.

Sidenote: javascript can only handle numbers upto 2**53 If you do the calculation, availableBorrowsETH is above this limit while daiPrice is below it.

Replies: 2 comments 5 replies

Comment options

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

Comment options

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

@othaime-en
Comment options

@TimeKeyRoll
Comment options

@othaime-en
Comment options

Answer selected by TimeKeyRoll
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