davedelong / DDMathParser

String → Number
MIT License
856 stars 153 forks source link

Unable to perform quick percetage calculations #86

Closed Sam1999 closed 10 years ago

Sam1999 commented 10 years ago

I'm trying to use the numberByEvaluatingString method to return results.

An example calculation:

100 * 10%

The expected result is 10

But it throws an error "no right operand to binary %"

Am I missing something or is there another way to perform these calculations?

davedelong commented 10 years ago

By default, % is interpreted as the modulo operator. In order for it to be interpreted as the percentage operator, you need to flip the DDMathOperatorSet.interpretsPercentSignAsModulo property to be NO. The easiest way to do that is on the default operator set:

[DDMathOperatorSet defaultOperatorSet].interpretsPercentSignAsModulo = NO;