I have a table with 4 fields in MySQL. 1 is product price cost 2 is price we sell 3 is stock of products 4 is earning by unit.
Cost of product for us 100, Selling price to customers is 120, Stock is 10 The follow code calculate the earnings by unit
<?php echo number_format($product['sellingprice'] - $product['cost'],0,',','.'); ?>
And it works fine it shows that the earnings we make by selling 1 unit is 20
now the problem, I need to calculate how much is the total earning by getting the earning for unit and multiplicate by stock ( 20 * 10 = 200 )
I am trying to do with the follow code
<?php echo number_format($product['sellingprice'] - $product['cost'] * $product['stock'],0,',','.'); ?>
But the result I get is wrong even with minus symbol like -23.454