Skip to content

Instantly share code, notes, and snippets.

@netstart
Last active December 23, 2019 18:16
Show Gist options
  • Save netstart/ed2f13963993b1abc05d to your computer and use it in GitHub Desktop.
Save netstart/ed2f13963993b1abc05d to your computer and use it in GitHub Desktop.
BigDecimalUtil.java
public class BigDecimalUtil {
public static int compareToIgnoreSignal(BigDecimal a, BigDecimal b) {
if (a.signum() < 0) a = a.multiply(new BigDecimal(-1));
if (b.signum() < 0) b = b.multiply(new BigDecimal(-1));
return a.compareTo(b);
}
public static Boolean isMinorThanIgnoreSignal(BigDecimal a, BigDecimal b) {
return compareToIgnoreSignal(a, b) < 0;
}
public static Boolean isGraterThanIgnoreSignal(BigDecimal a, BigDecimal b) {
return compareToIgnoreSignal(a, b) > 0;
}
public static Boolean isEqualsIgnoreSignal(BigDecimal a, BigDecimal b) {
return compareToIgnoreSignal(a, b) == 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment