|
@@ -31,33 +31,54 @@ public class BigDecimalUtil {
|
|
|
);
|
|
|
}
|
|
|
|
|
|
- public static Integer compareTo(BigDecimal a, BigDecimal b) {
|
|
|
- Integer res = 1;
|
|
|
+ //a小于b
|
|
|
+ public static Boolean lt(BigDecimal a, BigDecimal b) {
|
|
|
+ Boolean res = false;
|
|
|
if (a.compareTo(b) == -1) {
|
|
|
- res = 1;
|
|
|
- //System.out.println("a小于b");
|
|
|
+ res = true;
|
|
|
}
|
|
|
+ return res;
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
+ //a等于b
|
|
|
+ public static Boolean eq(BigDecimal a, BigDecimal b) {
|
|
|
+ Boolean res = false;
|
|
|
if (a.compareTo(b) == 0) {
|
|
|
- res = 2;
|
|
|
- //System.out.println("a等于b");
|
|
|
+ res = true;
|
|
|
}
|
|
|
+ return res;
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
+ //a大于b
|
|
|
+ public static Boolean gt(BigDecimal a, BigDecimal b) {
|
|
|
+ Boolean res = false;
|
|
|
if (a.compareTo(b) == 1) {
|
|
|
- res = 3;
|
|
|
- //System.out.println("a大于b");
|
|
|
+ res = true;
|
|
|
}
|
|
|
+ return res;
|
|
|
|
|
|
+ }
|
|
|
+
|
|
|
+ //a大于等于b
|
|
|
+ public static Boolean ge(BigDecimal a, BigDecimal b) {
|
|
|
+ Boolean res = false;
|
|
|
if (a.compareTo(b) > -1) {
|
|
|
- res = 4;
|
|
|
- //System.out.println("a大于等于b");
|
|
|
+ res = true;
|
|
|
}
|
|
|
+ return res;
|
|
|
|
|
|
+ }
|
|
|
+
|
|
|
+ //a小于等于b
|
|
|
+ public static Boolean le(BigDecimal a, BigDecimal b) {
|
|
|
+ Boolean res = false;
|
|
|
if (a.compareTo(b) < 1) {
|
|
|
- res = 5;
|
|
|
- //System.out.println("a小于等于b");
|
|
|
+ res = true;
|
|
|
}
|
|
|
return res;
|
|
|
+
|
|
|
}
|
|
|
|
|
|
public static void main(String[] args) {
|
|
@@ -69,5 +90,31 @@ public class BigDecimalUtil {
|
|
|
System.out.println(df2.format(a));
|
|
|
System.out.println(df.format(b));
|
|
|
System.out.println(df2.format(b));
|
|
|
+
|
|
|
+ System.out.println("====a小于b====");
|
|
|
+ System.out.println(lt(new BigDecimal(1.1), new BigDecimal(1)) == false);
|
|
|
+ System.out.println(lt(new BigDecimal(1), new BigDecimal(1)) == false);
|
|
|
+ System.out.println(lt(new BigDecimal(0.9), new BigDecimal(1)) == true);
|
|
|
+
|
|
|
+ System.out.println("====a等于b====");
|
|
|
+ System.out.println(eq(new BigDecimal(1.1), new BigDecimal(1)) == false);
|
|
|
+ System.out.println(eq(new BigDecimal(1), new BigDecimal(1)) == true);
|
|
|
+ System.out.println(eq(new BigDecimal(0.9), new BigDecimal(1)) == false);
|
|
|
+
|
|
|
+ System.out.println("====a大于b====");
|
|
|
+ System.out.println(gt(new BigDecimal(1.1), new BigDecimal(1)) == true);
|
|
|
+ System.out.println(gt(new BigDecimal(1), new BigDecimal(1)) == false);
|
|
|
+ System.out.println(gt(new BigDecimal(0.9), new BigDecimal(1)) == false);
|
|
|
+
|
|
|
+ System.out.println("====a大于等于b====");
|
|
|
+ System.out.println(ge(new BigDecimal(1.1), new BigDecimal(1)) == true);
|
|
|
+ System.out.println(ge(new BigDecimal(1), new BigDecimal(1)) == true);
|
|
|
+ System.out.println(ge(new BigDecimal(0.9), new BigDecimal(1)) == false);
|
|
|
+
|
|
|
+ System.out.println("====a小于等于b====");
|
|
|
+ System.out.println(le(new BigDecimal(1.1), new BigDecimal(1)) == false);
|
|
|
+ System.out.println(le(new BigDecimal(1), new BigDecimal(1)) == true);
|
|
|
+ System.out.println(le(new BigDecimal(0.9), new BigDecimal(1)) == true);
|
|
|
+
|
|
|
}
|
|
|
}
|