Im using the java scriptengine to evaluate the math of a string i have.
import javax.script.ScriptEngineManager;
import javax.script.ScriptEngine;
public class GraphYPosAlg
{
public static double YPos(String funktion) {
Double tempDouble;
ScriptEngineManager StringToInt = new ScriptEngineManager();
ScriptEngine engine = StringToInt.getEngineByName("JavaScript");
tempDouble = engine.eval(funktion);
return tempDouble;
}
}
I get the error "required: java.lang.Double, found: java.lang.Object" I need to convert the engine.eval(funktion); into a double but how?!?!?!?
Please describe much im pretty new to programming.
thanks in advance.
You could invoke the toString()
method on the object and create a double
out of it:
tempDouble = Double.parseDouble(engine.eval(funktion).toString());