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

Popular posts from this blog

Issues changing the value of an element in an array in matlab -

php - MySQLi binding parameters in a prepared statement doesn't work unless inserted after "WHERE" -

vb.net - Alternative to the T-SQL AS keyword -