Replies: 2 comments 5 replies
-
The scale of a BigDecimal is the number of decimal digits. So this is the same, isn't it? |
Beta Was this translation helpful? Give feedback.
-
I'm back with an issue that I think may be related to this entire thing. A user reported to me that math equations I cannot say why exactly this is happening. All I do is create a new For full context, the Code I'm using: public String getResult(String expression, int scale, String roundingMode){
RoundingMode mode = createRoundingMode(roundingMode);
ExpressionConfiguration config = ExpressionConfiguration.builder()
.mathContext(new MathContext(68, mode) // 68 is default precision (not scale) according to EvalEx docs
.decimalPlacesRounding(scale)
.build();
try{
return new Expression(expression, config).evaluate().getStringValue();
}catch(EvaluationException | ParseException ex){
System.out.println("Encountered issue while parsing expression " + expression);
ex.printStackTrace();
return null;
}
}
// I have this because input for rounding mode can't have underscores in my use-case.
private RoundingMode createRoundingMode(String roundingMode){
return switch(roundingMode.toLowerCase(Locale.ROOT)){
case "up" -> RoundingMode.UP;
case "down" -> RoundingMode.DOWN;
case "ceiling" -> RoundingMode.CEILING;
case "floor" -> RoundingMode.FLOOR;
case "half-down" -> RoundingMode.HALF_DOWN;
case "half-even" -> RoundingMode.HALF_EVEN;
default -> RoundingMode.HALF_UP;
};
} |
Beta Was this translation helpful? Give feedback.
-
I would like to have a bit of clarification regarding a specific method.
In Precision, Scale and Rounding do the docs show an example using
decimalPlacesRounding
.However, the text before the code block mentions automatic scaling, so my mind imediatally assumes the section after it is about scaling and not decimal points...
Am I right to assume that this assumption is wrong and that
decimalPlacesRounding
actually sets the decimal points of a number to display?Beta Was this translation helpful? Give feedback.
All reactions