- Import library to your code:
import static com.sunchp.utils.math.BigDecimalUtils.*;
- Doing comparison:
if(is(income).lt(amount)) {
// ....
}else {
// ...
}
- Do calculation:
remain = cal(income).minus(amount).result();
is(income).eq(amount); // Equal
is(income).gt(amount); // Greater than
is(income).gteq(amount); // Greater than equal
is(income).lt(amount); // Less than
is(income).lteq(amount); // Less than equal
cal(income).plus(amount) // addition
cal(income).minus(amount) // subtraction
cal(income).mul(amount) // multiply
cal(income).div(amount) // division
cal(income).div(amount,2) // division
Currently comparison support only String and BigDecimal:
is(bigdecimal).eq(bigdecimal); // BigDecimal and BigDecimal
is(bigdecimal).eq("1000"); // BigDecimal and String
is("1000").lt(bigdecimal); // String and BigDecimal
is("1000").lt("2000"); // String and String
Calculation support only String and BigDecimal:
cal(bigdecimal).minus(bigdecimal) // BigDecimal and BigDecimal
cal(bigdecimal).minus("500") // BigDecimal and String
cal("500").minus(bigdecimal) // String and BigDecimal
cal("1000").minus("500") // String and String