math - Java : how to get correct result? -
this question has answer here:
- integer division: how produce double? 10 answers
 
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
Post a Comment