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

How to run C# code using mono without Xamarin in Android? -

c# - SharpSsh Command Execution -

python - Specify path of savefig with pylab or matplotlib -