So I'm working on a big Java project and in it I have a part with user submitted equations, both mathematical and for things like If/else. I've been using a scriptengine with javascript to get the results. I've run into the issue of the floating point errors for rounding. For example math.pow(1000,1/3) returns 9.999999999999998 instead of 10. (before anyone says it, I'm aware of the cube root function this is just an example).
Basically I need a solution that gives the proper numbers. Whether this means a different scriptengine other than javascript or someway to tell the script to round all numbers off to x decimal places I don't know. I don't need 15 decimal places of precision so I can make that trade off but I don't know a practical way to implement this on the entire equation. The problem coming from the equation possibly being different each time. I'd also consider doing something like the shunting yard algorithm in java itself but it has the exact same problem. Basically I need to pass the code 1000^1/3 and know I'm getting 10.