标签:
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));
}
double由于是双精度,所以比较大小不能直接用>,<或者=,需要使用BigDecimal,具体看例子
标签:
原文地址:http://www.cnblogs.com/htys/p/5442287.html