I'm currently learning how to write smart contracts.
While studying some code, I came across this line:
uint256 a = value.ceil(basePercent);
(with: uint256 public basePercent = 100;)
Then one calculates 1% of the value with:
uint256 onePercent = a.mul(basePercent).div(10000);
But why was the first line of code necessary or what is it doing?
Best Answer
You can check with the code below that this line:
If your value
_value
is higher thanbasePercent
,roundValue
will be the number rounded on the hundred, otherwise the_value
will bebasePercent
always.Example:
input = 1
-->roundValue = 100
Example:
input = 4111
-->roundValue = 4200
Code:
Supposing a
SafeMath library
like the following:And the
onePercent
function: