Skip to content

Decimal Maths (e.g. division with fractional components) #1206

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

You must be logged in to vote

You can use the FixedNumber class for this:

a = FixedNumber.from("1.5");
b = FixedNumber.from("0.3");
b.divUnsafe(a).toString();

The BigNumber class is specifically for integers, while the fixed point math allows you to specify a format (by default "fixed128x18", which should suffice for most purposes).

Does that help?

Replies: 1 comment 1 reply

Comment options

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

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