November 2018
Intermediate to advanced
528 pages
13h 21m
English
Handling the division in the previous scenario is just the same as working with integer divisions, as Ethereum doesn’t adopt floating point numbers. The division would result in a floor of the calculation with the remainder discarded. For example, the division 17/3 equals 5, with the remainder of 2 discarded. To fix this, we create a new method that does the following:
function calcul(uint a, uint b, uint precision) public pure returns (uint) { require(b != 0); return a * (10 ** (precision)) / b;}Note that the double asterisk, **, is a Solidity operator representing the exponentiation operation. In our example, 10 is the base whereas precision is the exponent.
If we divide 17 by 3 using the calcul() function, and ...
Read now
Unlock full access