编程语言
首页 > 编程语言> > 【java】BigDecimal大于等于/小于等于/小于/大于/等于 比较器工具方法

【java】BigDecimal大于等于/小于等于/小于/大于/等于 比较器工具方法

作者:互联网

BigDecimal大于等于/小于等于/小于/大于/等于 比较器工具方法

 

public static void main(String[] args) {
        BigDecimal self = new BigDecimal("100");
        BigDecimal constant = new BigDecimal("99");

        System.out.println("大于等于结果:" + greater(self, constant, true));
        System.out.println("大于结果:" + greater(self, constant, false));
        System.out.println("小于等于结果:" + less(self, constant, true));
        System.out.println("小于结果:" + less(self, constant, false));
        System.out.println("等于结果:" + equals(self, constant));


    }

    public static Boolean less(BigDecimal self, BigDecimal constant, boolean needEqual) {
        if (needEqual) {
            return  self.compareTo(constant) < 1 ;
        }else {
            return self.compareTo(constant) == -1;
        }
    }

    public static Boolean greater(BigDecimal self, BigDecimal constant, boolean needEqual) {
        if (needEqual) {
            return  self.compareTo(constant) > -1 ;
        }else {
            return self.compareTo(constant) == 1;
        }
    }

    public static Boolean equals(BigDecimal self, BigDecimal constant) {
        return self.compareTo(constant) == 0;
    }
View Code

 

标签:小于,constant,BigDecimal,self,System,return,等于,大于,out
来源: https://www.cnblogs.com/sxdcgaq8080/p/16306486.html