A DESCRIPTION OF THE PROBLEM :
The issue only happens when the quotient as a negative scale.
In that case, the values of the quotient and dividend seems to be ignored, and:
10^ |scale| is returned when RoundingMode.UP is used.
0 is returned when RoundingMode.HALF_EVENis used.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
BigDecimal quotient = new BigDecimal("300").setScale(-2,RoundingMode.UP);
BigDecimal dividend = new BigDecimal("100");
System.out.println(quotient.divide(dividend,RoundingMode.UP).toPlainString());
---------- BEGIN SOURCE ----------
package com.melo;
import java.math.BigDecimal;
import java.math.RoundingMode;
public class BigDecimalTester {
public static void main(String[] args) {
BigDecimal quotient = new BigDecimal("300").setScale(-2, RoundingMode.UP);
BigDecimal dividend = new BigDecimal("100");
System.out.println(quotient.divide(dividend, RoundingMode.UP).toPlainString());
System.out.println(quotient.divide(dividend).toPlainString());
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Do not specify a RoundingMode seems to avoid the issue
FREQUENCY : always
The issue only happens when the quotient as a negative scale.
In that case, the values of the quotient and dividend seems to be ignored, and:
10^ |scale| is returned when RoundingMode.UP is used.
0 is returned when RoundingMode.HALF_EVENis used.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
BigDecimal quotient = new BigDecimal("300").setScale(-2,RoundingMode.UP);
BigDecimal dividend = new BigDecimal("100");
System.out.println(quotient.divide(dividend,RoundingMode.UP).toPlainString());
---------- BEGIN SOURCE ----------
package com.melo;
import java.math.BigDecimal;
import java.math.RoundingMode;
public class BigDecimalTester {
public static void main(String[] args) {
BigDecimal quotient = new BigDecimal("300").setScale(-2, RoundingMode.UP);
BigDecimal dividend = new BigDecimal("100");
System.out.println(quotient.divide(dividend, RoundingMode.UP).toPlainString());
System.out.println(quotient.divide(dividend).toPlainString());
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Do not specify a RoundingMode seems to avoid the issue
FREQUENCY : always