math - Java : how to get correct result? -


this question has answer here:

in java:

double b = 1234 / (1234+1500); 

result is:

0.0 

why?

how correct result?

just make 1 of operand double/float -

double b = (double) 1234.0/(1235+1500); 

here casting not required.

the rules benind: if 1 of operand double/float (here 1234.0) other promoted double/float.


Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -