public static String compare(BigDecimal val1, BigDecimal val2)
{ String result = ""; if (val1.compareTo(val2) < 0)
{ result = "第二位数大!"; }
if (val1.compareTo(val2) == 0)
{ result = "两位数一样大!"; }
if (val1.compareTo(val2) > 0) {
result = "第一位数大!";
}
return result; }
public static void main(String[] args)
{
double a = 1.124; double b = 1.12345679;
BigDecimal data1 = new BigDecimal(a);
BigDecimal data2 = new BigDecimal(b);
System.out.print(compare(data1, data2));
}