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 nsexpression
not 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
Post a Comment