java - What does ceill floor in this code mean? -
can explain me code mean? in if/else. have read documentation several times, can't these functions mean. thanks.
private long getbalancewithfactor(long balance, double factor) { double faccountbalance = (double)balance * factor; long res = 0; if ((math.ceil(faccountbalance) - faccountbalance) <= 0.5) res = (long)math.ceil(faccountbalance); else res = (long)math.floor(faccountbalance); return res; }
math.ceil()
rounds up, math.floor()
rounds down nearest integer.
so example if give 0.5
ceil(0.5)
return 1.0
, , floor(0.5)
return 0.0
.
there useful function in context: math.round()
ceil()
, floor()
combined. rounds nearest integer using mathematical rounding rules.
please note these methods return doubles you'll need cast them integers.
Comments
Post a Comment