关于Bigdecimal比较大小

java中对bigdimical比较大小一般用的是bigdemical的compareTo方法;

int a = bigdemical.compareTo(bigdemical2);
a = 1,表示bigdemical大于bigdemical2;
a = 0,表示bigdemical等于bigdemical2;
a = -1,表示bigdemical小于bigdemical2;

 另,

@org.junit.Test
    public void bigdecimalTest(){
        BigDecimal a=BigDecimal.valueOf(1.0);
        BigDecimal b=BigDecimal.valueOf(1.000);

        System.out.println("a:"+a+";b="+b);//a:1.0;b=1.0
        System.out.println(a.equals(b));//true
        System.out.println(a.compareTo(b)==0);//true

        BigDecimal c = new BigDecimal("1.0");
        BigDecimal d = new BigDecimal("1.000");
        System.out.println("c:"+c+";d="+d);//c:1.0;d=1.000
        System.out.println(c.equals(d));//false
        System.out.println(c.compareTo(d)==0);//true

}

 

posted @ 2018-09-16 23:30  习惯沉淀  阅读(9594)  评论(0编辑  收藏  举报