.toString
vs toNumber
confusion
#2724
-
Hi! We are using
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
The tostring() function converts a number to a string The tonumber() function converts a string to a number |
Beta Was this translation helpful? Give feedback.
-
Hey @TimeKeyRoll the difference with the way we use Sidenote: javascript can only handle numbers upto |
Beta Was this translation helpful? Give feedback.
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()
onavailableBorrowsETH
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 whiledaiPrice
is below it.