-
Bug
-
Resolution: Not an Issue
-
P4
-
None
-
8u111
-
generic
-
generic
FULL PRODUCT VERSION :
java version "1.8.0_111"
Java(TM) SE Runtime Environment (build 1.8.0_111-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.111-b14, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]
A DESCRIPTION OF THE PROBLEM :
if we have a BigDecimal with 3 or more digits after the decimal point, and we call
the setScale method with 2 , then it gives exception.
See example below
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
given the example no exception should be generated .
a default Rounding mode should be used inside the method.
ACTUAL -
exception is generated unexpectadly
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.math.BigDecimal;
public class BigDecimalSetScale {
public static void main(String[] args) {
BigDecimal epoSacAmt0 = new BigDecimal("1.340") ;
BigDecimal one = new BigDecimal("0.001") ;
for (int i=0; i < 10 ; i ++){
try {
epoSacAmt0 = epoSacAmt0.add(one);
epoSacAmt0.setScale(2);
}catch(Exception e){
System.out.println("exception " +e+" with "+epoSacAmt0);
}
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
use setScale(int, roundingMode) always
java version "1.8.0_111"
Java(TM) SE Runtime Environment (build 1.8.0_111-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.111-b14, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]
A DESCRIPTION OF THE PROBLEM :
if we have a BigDecimal with 3 or more digits after the decimal point, and we call
the setScale method with 2 , then it gives exception.
See example below
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
given the example no exception should be generated .
a default Rounding mode should be used inside the method.
ACTUAL -
exception is generated unexpectadly
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.math.BigDecimal;
public class BigDecimalSetScale {
public static void main(String[] args) {
BigDecimal epoSacAmt0 = new BigDecimal("1.340") ;
BigDecimal one = new BigDecimal("0.001") ;
for (int i=0; i < 10 ; i ++){
try {
epoSacAmt0 = epoSacAmt0.add(one);
epoSacAmt0.setScale(2);
}catch(Exception e){
System.out.println("exception " +e+" with "+epoSacAmt0);
}
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
use setScale(int, roundingMode) always