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

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -