Java - simple division in Java ---> bug?!
Posted
by msr
on Stack Overflow
See other posts from Stack Overflow
or by msr
Published on 2010-05-26T00:29:53Z
Indexed on
2010/05/26
0:41 UTC
Read the original article
Hit count: 320
Hello,
Im astonished. Im trying this simple calculation in a Java application:
System.out.println("b=" + (1 - 7/10));
Obviously Im wainting for "b=0.3" in the output but here's what I get:
b=1
What?! Why this happens?
If I make:
System.out.println("b=" + (1-0.7));
I get the right result which is "b=0.3".
What's going wrong here?
Thanks!
© Stack Overflow or respective owner