Hi,
I am using commons-jexl 2.1.1 and noticed that expression evaluation for below
to be different.
//returns 55.87999 incorrectly
formula = "#{(9/5 * celcius )+32}";
formula = formula.substring(2, formula.length()-1);//strip prefix #{ and suffix
}
map.put("celcius", 23.88);
//returns 75 correctly
formula = "#{(celcius * 9/5)+32}";
formula = formula.substring(2, formula.length()-1);//strip prefix #{ and suffix
}
map.put("celcius", 23.88);
Here is method used to evaluate:
public static Double evaluate(String formula, Map<String,Double> ctxParam) {
JexlEngine jexl = new JexlEngine();
org.apache.commons.jexl2.Expression e = jexl.createExpression(formula);
JexlContext ctx = new MapContext();
for(Map.Entry<String, Double> me : ctxParam.entrySet()) {
ctx.set(me.getKey(), me.getValue().toString());
}
Object result = e.evaluate(ctx);
return Double.parseDouble(result.toString());
}
is there some rules for how we form the expression ?
Regards,
Miten.