Does anyone know why I am getting strange results when using the % operator. (It could be on other things as well, but this is when I noticed it.)
I'm running Win 98, Sun JDK1.3, compiled at dos prompt using javac and ran at dos prompt using java. Following is the simple program I used to pinpoint the error and the output.
[tt]
class Modulus
{
public static void main (String args[])
{
int x = 42;
double y = 42.3;
System.out.println("x mod 10 = " + x % 10);
System.out.println("y mod 10 = " + y % 10);
}
}
[/tt]
OUTPUT
x mod 10 = 2
y mod 10 = 2.99999999999997
Thanks,
tone
I'm running Win 98, Sun JDK1.3, compiled at dos prompt using javac and ran at dos prompt using java. Following is the simple program I used to pinpoint the error and the output.
[tt]
class Modulus
{
public static void main (String args[])
{
int x = 42;
double y = 42.3;
System.out.println("x mod 10 = " + x % 10);
System.out.println("y mod 10 = " + y % 10);
}
}
[/tt]
OUTPUT
x mod 10 = 2
y mod 10 = 2.99999999999997
Thanks,
tone