java - Round up when multiplying an integer by 0.5 -
this question has answer here:
- always round double 7 answers
is there way automatically round value in java?
for example:
//generate random integer value int randomval = randomhelper.nextintfromto(1, otherval); /* divide integer value in half... error getting double, because number generated isn't number, need integer. can round up?*/ int value = randomval * 0.5;
use math.ceil()
:
int value = (int)math.ceil(randomval * 0.5);
Comments
Post a Comment