Return-Path: X-Original-To: apmail-commons-user-archive@www.apache.org Delivered-To: apmail-commons-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 75845D43A for ; Wed, 22 Aug 2012 09:49:11 +0000 (UTC) Received: (qmail 74583 invoked by uid 500); 22 Aug 2012 09:49:10 -0000 Delivered-To: apmail-commons-user-archive@commons.apache.org Received: (qmail 74105 invoked by uid 500); 22 Aug 2012 09:49:09 -0000 Mailing-List: contact user-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Commons Users List" Delivered-To: mailing list user@commons.apache.org Received: (qmail 74074 invoked by uid 99); 22 Aug 2012 09:49:08 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 22 Aug 2012 09:49:08 +0000 X-ASF-Spam-Status: No, hits=-0.7 required=5.0 tests=RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of sebbaz@gmail.com designates 209.85.220.171 as permitted sender) Received: from [209.85.220.171] (HELO mail-vc0-f171.google.com) (209.85.220.171) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 22 Aug 2012 09:49:01 +0000 Received: by vcdd16 with SMTP id d16so1055707vcd.30 for ; Wed, 22 Aug 2012 02:48:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=4pqawT0J5WXikwUgpfPuFdnkeZQWh2o33FGsyssirGY=; b=dYjMpeXu/Ppf1P/5Zscl93UsvRCMngd3Bb52S/h7Vb8EvHqmft+F1iTj1+lv8pBkMC X3eDdobKVxmYVNxGePde9hqr3f99mCDh4Q+eCn+gKklzeCDICSbyi8MAv65iY4w/hTCQ PtLFQp2t1Oaa7RbyazMdhVsXpoKNIn1DUqx1spuOlgTf/TtrlMmyHIVdkpvf2ustI0mB GgxBl+8/Sjqx9llSOPGVS4UBhw1fliLUWE2LEbWVmklAe8zvyqcnt3VxmLv05kZodgIF LQ7CSNjrUssLQo5+IAT/pekeTChAFi0DnImkSr4uJXbMdGGBZJFUIJBTTI6L2r0jucEw 0Wtw== MIME-Version: 1.0 Received: by 10.220.214.205 with SMTP id hb13mr16238439vcb.28.1345628920480; Wed, 22 Aug 2012 02:48:40 -0700 (PDT) Received: by 10.58.58.197 with HTTP; Wed, 22 Aug 2012 02:48:40 -0700 (PDT) In-Reply-To: <1345615263.29762.YahooMailNeo@web161802.mail.bf1.yahoo.com> References: <1345615263.29762.YahooMailNeo@web161802.mail.bf1.yahoo.com> Date: Wed, 22 Aug 2012 10:48:40 +0100 Message-ID: Subject: Re: [JEXL] unexpected expression evaluation From: sebb To: Commons Users List , miten mehta Content-Type: text/plain; charset=ISO-8859-1 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 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 ctxParam) { > JexlEngine jexl = new JexlEngine(); > org.apache.commons.jexl2.Expression e = jexl.createExpression(formula); > JexlContext ctx = new MapContext(); > for(Map.Entry 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: user-unsubscribe@commons.apache.org For additional commands, e-mail: user-help@commons.apache.org