java - Round up when multiplying an integer by 0.5 -


this question has answer here:

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

Popular posts from this blog

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -

javascript - Using jquery append to add option values into a select element not working -

javascript - Restarting Supervisor and effect on FlaskSocketIO -