Home > OS >  Formula to calculate balance when values are negative
Formula to calculate balance when values are negative

Time:09-27

Earning = 10 Withdrawn = -30

Balance = Earning - Withdrawn = 10 - (-30) = 40 The correct value should be -20

How to do it in php if both or either of above values is negative?

CodePudding user response:

you can add a check, to see if the value is negative, and then, u can do this:

$a = 10;
$b = -30;
$op = ($a) - abs($b);

echo "$op";

It will return -20

https://www.w3schools.com/php/func_math_abs.asp

CodePudding user response:

Yop, next time say "hello" at least

  •  Tags:  
  • php
  • Related