Double to Integer conversion
Need your help, please.
For the precision, I made the key variables type of "double".
However, when I complete the calculation, I wanted to get the integer portion only by truncating below the decimal point.I tried to use (int) () command.
However, compiler complains that I will loose the precision and does not compile. I wanted to loose by truncation...... What am I doing wrong?
Can you help , please?
Thanks
Kim
[459 byte] By [
qls_kima] at [2007-11-26 20:15:48]

For our discussion, I copy the code from fast convergence calculation below.This may be terrible way of doing it but the code runs OK as long as I do not try to convert the double variable to integer.
It gives error message saying 搃ntValue[] in java.lang.Number.intValue can not be applied to double?
My question is what is the proper way of getting positive integer from double variable? I just wanted to get rid of the sign and truncate below the decimal point.Thanks.
while (n < 50) {
top = java.lang.Math.pow (-1, n);
bottom = java.lang.Math.pow (3.0, n) * (2*n +1);
top = (top / bottom) * factor;
pi = pi + top;
value = pi * co;
// need to truncate below the decimal (or pick interger portion)
//current = java.lang.Number.intValue (pi);
//System.out.println ("current =" + current);
//if(current == last) {
System.out.print ("pi = " + value);
System.out.println ("top = " + top);
n = n+1;
if (top == 0) {
System.out.println ("n =" + n);
break;
}
}