D12L12 D12L12 - 4 years ago 112
PHP Question

PHP Mathematical Equation With Percentages

How can I write this equation.

Pretty much here is what I have

(float) $total = (float) $product_price * (float) $percentage;
return (float) $total;

Although now I need to add a country percentage. Therefore if the country percentage is 10% I need to add 10% onto the current total and return it.

I use the variable $country_percentage

Answer Source

If I understand correctly, you want to add the percentage (tax?) to the total. If the $country_percentage is the integer '10', that would equate to '0.10'

($total * (1 + ($country_percentage / 100))

Which would be ($total * 1.10)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download