Apr
15
|
Java introduced scripting support with Java 6.
Heres a simple example showing how to use the JavaScript scripting engine to evaluate an expression.
ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName("JavaScript"); Object result = engine.eval("6 * (3 + 5)");
Array ( ) 2 Responses to “Evaluate expression”
Leave a Reply
You must be logged in to post a comment.
May 10th, 2011 at 4:43 am
Hi
i was using in the same way and my expression is some thing like that 1/11. I was expecting 0.090 as result but it is returning 1. So the question is how to return value in decimal?
Thanks
Shuja
May 10th, 2011 at 9:00 am
Try 1.0 / 11.0