两个double类型的值比大小


package wxText; import java.math.BigDecimal; public class DoubleDemo { public 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 = 0.01; double b = 0.01; BigDecimal data1 = new BigDecimal(a); BigDecimal data2 = new BigDecimal(b); System.out.print(new DoubleDemo().compare(data1, data2)); } }

 

上一篇:Oracle中 创建视图的同时新增字段(常用函数:decode,NVL,NVL2)


下一篇:前端用JQ生成JSON字符串