Change if (res == 0)
to if (Math.abs(res) <= 0.000000001)
You can probably just declare res as an int, also:
int res = (int)(diff % inc);
-- Jeff
Phani wrote:
Sorry this is not a struts question..more anlytical..
I have this simple program where I want to check whether the division operation returns a whole number or not...For this purpose I am actually checking whether the remainder is zero..which fails for a particular case..
Here is my program below..Hope to get any help ..
Thanks.
public class ROPTest {
public double d1 = 0.0; public double d2 = 1.0; public double inc = 0.1;
public double diff; public double res;
public ROPTest() {
}
/* This function is to verify whether the division operation --> diff/inc returns a whole number or not */
public void compute() {
double diff = d2 - d1; res = diff%inc;
if(res == 0) System.out.println("The Result is Zero: "+res); else System.out.println("The Result is not Zero: "+res);
}
public static void main(String args[]) {
ROPTest rt = new ROPTest();
rt.compute();
}
}
__________________________________ Do you Yahoo!? The all-new My Yahoo! - Get yours free! http://my.yahoo.com
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]