Have a look at commons-jexl:
http://jakarta.apache.org/commons/jexl/

import org.apache.commons.jexl.*;

public class JexlExample {

    public static void main(String[] args)  throws Exception {
        String expr = "((123*123+567-7899*340)/1234)*1000";
        Expression e = ExpressionFactory.createExpression(expr);
        JexlContext context = JexlHelper.createContext();
        // here you'd populate your context if you had any variables...
        Object result = e.evaluate(context);
        System.out.println("result: " + result);
    }
}



At 9:11 AM +1100 1/5/05, Apurva Goswami wrote:
Hi Sachin,

Haven't tried but have a look at these links:

http://jakarta.apache.org/poi/apidocs/org/apache/poi/hssf/model/FormulaP
arser.html


http://maplenet.maplesoft.com/doc/com/maplesoft/maplenet/client/MapleSta tement.html


Cheers Apurva


-----Original Message----- From: sachin [mailto:[EMAIL PROTECTED] Sent: Tuesday, January 04, 2005 6:14 PM To: Struts Users Mailing List Subject: RE: Help : execute a equation in String format

hi apurva ,

To be precise you can java.math.BigDecimal and then convert your
result
into string object.

Thanks for ur reply . The equation builder can be achieved this way. But if the query is complex it takes a long way ... like looking for the

innermost brackets, aplying square roots , squares , * , / , + , -  etc
..and
more .

So i was looking for some library class which can take an arithmetic
equation
and deliver its result .. but if this sort of thing is not available  ..
then
i will have to develope it.

Regards,
Sachin Hegde
Software Developer
Paradyne Infotech Limited , Mumbai
09324546711

"The believer is happy. The doubter is wise." -Benjamin Disraeli

---------- Original Message -----------
From: "Apurva Goswami" <[EMAIL PROTECTED]>
To: "Struts Users Mailing List" <user@struts.apache.org>
Sent: Tue, 4 Jan 2005 17:28:43 +1100
Subject: RE: Help : execute a equation in String format

 Hi Sachin,

 You can use java.math class to achieve what you want.
 To be precise you can java.math.BigDecimal and then convert your
result
 into string object.

 Hope this helps.

 Cheers
 Apurva

 -----Original Message-----
 From: sachin [mailto:[EMAIL PROTECTED]
 Sent: Tuesday, January 04, 2005 5:34 PM
 To: Struts Users Mailing List
 Subject: Help : execute a equation in String format

 hi ,

 I have equation in String format
 like

> String equ = "((123*123+567-7899*340)/1234)*1000";

now i want to execute this equation and get the result .. How can i achieve this in java ?

 note : This is not a struts -related issue ... yet i need help so i
 posted ..
 hope nobody minds much ....

 Regards,
 Sachin Hegde
 Software Developer
 Paradyne Infotech Limited , Mumbai
 09324546711

 "There are three kinds of lies: lies, damn lies, and statistics."
 -Benjamin Disraeli

 ---------------------------------------------------------------------
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]

 ---------------------------------------------------------------------
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
------- End of Original Message -------


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]


--
Joe Germuska [EMAIL PROTECTED] http://blog.germuska.com "Narrow minds are weapons made for mass destruction" -The Ex


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to