Code example for BigDecimal

Methods: compareTo, divide

0
    public BigDecimal getTotalOrderPrice() {
        return totalOrderPrice;
    } 
 
    public BigDecimal getTotalVariance() {
        if (totalOrderPrice.compareTo(BigDecimal.ZERO) > 0) {
            return BigDecimal.ONE.subtract(totalOrderPrice.divide(totalQuote, 4, RoundingMode.HALF_UP)).multiply(new BigDecimal("100")).setScale(2);
        } else { 
            return BigDecimal.ZERO;
        } 
    } 
 
    public BigDecimal getTotalQuote() {
        return totalQuote;
    } 
}