Hi kenchan2000,
Usual way for tackel precision is Use java.math package.
i.e. use BigInteger or BigDecimal class. It allow U to round the values to your requried position.
Generic Example:
/*********************** code **************************
import java.math.*;
public class Square
{
public static void main (String args[])
{
double val = 1.13;
int denominator = 1;
int precision=3;
System.out.println("Square
try {
BigDecimal bigDinom = new BigDecimal(denominator);
BigDecimal doubleVal = new BigDecimal(val);
doubleVal = doubleVal.divide(bigDinom,
System.out.println("Square
val = doubleVal.doubleValue();
System.out.println("Square
} catch(ArithmeticException ae){
System.out.println("Err" + ae.getMessage());
}
}
}
/********************* End code **************************
Hope this will help you.
Main Topics
Browse All Topics





by: heyhey_Posted on 2002-02-26 at 01:18:58ID: 6826904
> java Square
Square is : 1.2769
what's the problem ?