objective c - Doing math with NSExpression using parenthsis -


i haven nsstring @"200 * (1 + (5 / 100))",

when put nsexpression *expression = [nsexpression expressionwithformat:mystring];

and nslog expression returns string. when call [[expression expressionvaluewithobject:nil context:nil] doublevalue] result of 200.

can nsexpressionnot handle 2 sets of parenthesis? solution using nsexpression - don't want use of mathlibraries, because have simple math equations.

thanks

of course can handle 2 sets of brackets, problem in types of values.

when write 200 * (1 + (5 / 100)) these values treated integers, , integer arithmetic used. means 5 / 100 evaluates 0 , that's why 200 result. if 5.0 / 100 (notice decimal point), you'd getting right result, division treated float division.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -