MCPcopy Create free account
hub / github.com/questdb/questdb / round

Method round

core/src/main/java/io/questdb/std/Decimal128.java:1077–1112  ·  view source on GitHub ↗

Round this Decimal128 to the specified scale using the given rounding mode. This method performs in-place rounding without requiring a divisor. @param targetScale the desired scale (number of decimal places) @param roundingMode the rounding mode to use @throws NumericException if targetScale is in

(int targetScale, RoundingMode roundingMode)

Source from the content-addressed store, hash-verified

1075 * @throws NumericException if roundingMode is UNNECESSARY and rounding is required
1076 */
1077 public void round(int targetScale, RoundingMode roundingMode) {
1078 if (isNull()) {
1079 return;
1080 }
1081
1082 if (targetScale == this.scale) {
1083 // No rounding needed
1084 return;
1085 }
1086
1087 validateScale(targetScale);
1088
1089 if (isZero()) {
1090 this.scale = targetScale;
1091 return;
1092 }
1093
1094 if (this.scale < targetScale) {
1095 boolean isNegative = isNegative();
1096 if (isNegative) {
1097 negate();
1098 }
1099
1100 // Need to increase scale (add trailing zeros)
1101 int scaleIncrease = targetScale - this.scale;
1102 multiplyByPowerOf10InPlace(scaleIncrease);
1103 this.scale = targetScale;
1104
1105 if (isNegative) {
1106 negate();
1107 }
1108 return;
1109 }
1110
1111 divide(0, 1, 0, targetScale, roundingMode);
1112 }
1113
1114 /**
1115 * Set the scale forcefully without doing any rescaling operations

Callers 12

testRoundMethod · 0.95
testRoundAllModesMethod · 0.95
testRoundFuzzMethod · 0.95
testRoundNegativeMethod · 0.95
testRoundNoChangeMethod · 0.95
testRoundNullMethod · 0.95
testRoundZeroMethod · 0.95

Calls 7

isNullMethod · 0.95
validateScaleMethod · 0.95
isZeroMethod · 0.95
isNegativeMethod · 0.95
negateMethod · 0.95
divideMethod · 0.95

Tested by 12

testRoundMethod · 0.76
testRoundAllModesMethod · 0.76
testRoundFuzzMethod · 0.76
testRoundNegativeMethod · 0.76
testRoundNoChangeMethod · 0.76
testRoundNullMethod · 0.76
testRoundZeroMethod · 0.76