-1

Can someone please tell if I can in PHP evaluate math expression to number? For example I have expresssion: (20 + 40%) + 20% I would get 33.6

I tried using EvalMath class from here: https://www.phpclasses.org/package/2695-PHP-Safely-evaluate-mathematical-expressions.html but it doesn't do the trick

1 Answers1

0

Thats just simple math.

If you have an expression $x + $y% - thats the same as $x + (1 + $y/100).

In your case, you could just write

$y = 20;
$x = $y * 1.4 * 1.2;
Philipp
  • 15,377
  • 4
  • 35
  • 52
  • But how I could for example parse this - (40 + 21%) * (500 -25%) - 25 and so on. Variable count is not limited for now only allowed symbols (+,-,*,/). I would need to split this in smaller equations, right? 1=> 40*1.21 2=>500 * 0.75 3=> 1) * 2) 4=> 3) - 25 – DoubleT Apr 10 '17 at 11:40