Updating to RoundingMode.Floor to avoid arithmetic overflow for max value(999..)
@@ -49,15 +49,12 @@ public class SqlDecimal extends SqlType {
}
// called from money/smallmoney
- SqlDecimal(String name, int precision, int scale, Object min, Object max,
- VariableLengthType variableLengthType) {
+ SqlDecimal(String name, int precision, int scale, Object min, Object max, VariableLengthType variableLengthType) {
this(name, JDBCType.DECIMAL, precision, scale, min, max, variableLengthType);
}
- SqlDecimal(String name, JDBCType jdbctype, int precision, int scale, Object min, Object max,
- VariableLengthType variableLengthType) {
- super(name, jdbctype, precision, scale, min, max, SqlTypeValue.DECIMAL.nullValue,
- variableLengthType);
+ SqlDecimal(String name, JDBCType jdbctype, int precision, int scale, Object min, Object max, VariableLengthType variableLengthType) {
+ super(name, jdbctype, precision, scale, min, max, SqlTypeValue.DECIMAL.nullValue, variableLengthType);
// update random precision and scale
generatePrecision();
@@ -78,29 +75,26 @@ public class SqlDecimal extends SqlType {
double lowerBound = 0;
double upperBound = 1;
-
/**
- * value to add for Math.random() to include upperBound - to choose
- * random value between 0 to 1 (inclusive of both)
+ * value to add for Math.random() to include upperBound - to choose random value between 0 to 1 (inclusive of both)
*/
double incrementValue = 0.1d;
Boolean inValidData = true;
BigDecimal randomValue = null;
while (inValidData) {
- randomValue = new BigDecimal(ThreadLocalRandom.current().nextDouble(lowerBound,
- upperBound + incrementValue));
+ randomValue = new BigDecimal(ThreadLocalRandom.current().nextDouble(lowerBound, upperBound + incrementValue));
Boolean isNegative = (0 == ThreadLocalRandom.current().nextInt(2)) ? true : false;
// Restrict the BigInteger to the length of precision
// i.e., if the precision is say 5, then get unscaledRandom%10^5
- if (randomValue.compareTo(new BigDecimal("1")) > 0) {
+ if (randomValue.compareTo(new BigDecimal("1")) >= 0) {
randomValue = randomValue.movePointRight(precision - scale - 1);
}
else {
randomValue = randomValue.movePointRight(precision - scale);
}
- randomValue = randomValue.setScale(scale, RoundingMode.HALF_DOWN);
+ randomValue = randomValue.setScale(scale, RoundingMode.FLOOR);
randomValue = (isNegative) ? randomValue.multiply(new BigDecimal("-1")) : randomValue;
