I'm using this project ( https://github.com/APISENSE/rhino-android ) to make calculations in my Android app.
However, some numbers starting with 0 in the expression causes a strange behavior in the calculation. For example:
Other examples that looks ok:
Code sample:
String expression = "016+2";
ScriptEngine engine = new ScriptEngineManager().getEngineByName("rhino");
double result = (double) engine.eval(expression);
Any ideas?
In JavaScript, putting a 0 in front of an integer will cast it to octal, as well as 0x will cast it as hexadecimal and 0b as binary.
This behavior does not take place if there is an 8 or a 9 in your integer since the cast to octal is impossible in this case.
So the behavior here seems completely normal for JavaScript. So I need to treat my expression to avoid this.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.