Is there a way to specify rounding precision when evaluating math operation using SpEL? For example
ExpressionParser parser = new SpelExpressionParser();
Expre
This works for me:
"2.0/3"
and result is 0.6666666666666666.
Does it make sense?
The point of the getValue(Double.class) is eliminated here since your 2/3 is just an operation between two integers and the result is an integer as well - 0.
And only after that this result is converted to expected double as a 0.0.
You need to explicitly say in the expression that you are going to deal with doubles.
You may consider this as a limitation, but getValue(Double.class) is not a casting operation like in Java. It is a post-conversion. Therefore precision is just lost because your expression evaluates to integer anyway.