This list is shared by lots of components; please use the appropriate prefix (added to this message) otherwise it may be overlooked by those who can help.
On 22 August 2012 07:01, miten mehta <[email protected]> wrote: > 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. --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
