Skip to content

BigNumber.div(divisor) doesn't return the good result #1407

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

You must be logged in to vote

BigNumber only operates on integers. Values are rounded toward zero.

If you are trying to perform fixed-point maths, you must use the FixedNumber object. They are much more complex to work with though, as you must consider the field in which they are operating.

E.g.

homestead> FixedNumber.from("52240126807063116261284835", "fixed80x18").divUnsafe(FixedNumber.from("32446080116944622871630", "fixed80x18")).toString()
'1610.059724280260943834'

Is that what you were looking for? If so, check out the docs. You should also familiarize yourself with the various caveats of using fixed-point math. There is a lot of complexity when dealing with decimal components...

Let me know if that helps. :)

Replies: 5 comments 8 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by ricmoo
Comment options

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

Comment options

You must be logged in to vote
7 replies
@ricmoo
Comment options

@iboxgithub
Comment options

@CodeForcer
Comment options

@ricmoo
Comment options

@iboxgithub
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
Converted from issue

This discussion was converted from issue #1405 on March 27, 2021 01:55.