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

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

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -