1

I use the code below to make my scriptEngine. It worked fine until I tried to do calculations containing doubles. The code below should return 30 but instead returns 5. Am I doing something wrong or can the scriptEngine just not do doubles?

 String calculation = "20*1.5";
 ScriptEngineManager mgr = new ScriptEngineManager();
 ScriptEngine engine = mgr.getEngineByName("JavaScript");
 String s = engine.eval(calculation).toString();
 System.out.println("Test: " + s);
 double answer = Double.parseDouble(s);
 System.out.println("Answer: \t" + answer);
Maiko Kingma
  • 929
  • 3
  • 14
  • 29

0 Answers0