BigDecimal进行比较

 public int compareTo(BigDecimal val) {
        // Quick path for equal scale and non-inflated case.
        if (scale == val.scale) {
            long xs = intCompact;
            long ys = val.intCompact;
            if (xs != INFLATED && ys != INFLATED)
                return xs != ys ? ((xs > ys) ? 1 : -1) : 0;
        }
        int xsign = this.signum();
        int ysign = val.signum();
        if (xsign != ysign)
            return (xsign > ysign) ? 1 : -1;
        if (xsign == 0)
            return 0;
        int cmp = compareMagnitude(val);
        return (xsign > 0) ? cmp : -cmp;
    }

eg:

a.comparedTo (b)

  如果a大于b返回1;

 如果a小于b返回-1;

如果a等于b返回0;

 

posted @ 2018-07-02 10:34  逝年的我们  阅读(2927)  评论(0编辑  收藏  举报