I have an expression from the strCal string strcal value is @”((24 – 18) / 87) * 100″
I want to have the result correct to 4 decimal so I retrieve the result using floatValue method
But instead of 6.8966 I get 0
This is my code
NSString *strCal=[NSString stringWithFormat:@"
((%d%@)%@)%@",number,strMinus,strDivide,strMultiple];
NSExpression *exp=[NSExpression expressionWithFormat:strCal];
float result=[[exp expressionValueWithObject:nil context:nil] floatValue];
NSLog(@"result:%f",result);
result:0.000000
I found it myself by converting the 87 in the string strCal to float value like below
@”((24 – 18) / 87.00) * 100″
why because means the either the dividend or divisor has to be in float so that the compiler(LLVM) output the answer in float