Proper way to do calculations using PHP? -


i need calculate ex_vat echo result need calculate inc_vat echo result.

it needs rounded 2 decimal places.

basically doesn't work, calculation nothing displays:

£29.17 inc vat £29.1700 ex vat

i don't know proper syntax this, why i'm asking on here, thanks!

code:

$req4 = $con->query("select price, vat_rate product product_id='$prodid'"); $row4 = $req4->fetch_row();  $price_ex_vat = $row4[0]; $vat_rate = $row4[1]; $price_inc_vat = 0; $price_inc_vat = $price_ex_vat + ($price_inc_vat * $vat_rate / 100); 

in line

$price_inc_vat = $price_ex_vat + ($price_inc_vat * $vat_rate / 100); 

you calling variable "$price_inc_vat" not existing yet. may want assign value variable before using it.

like

$price_inc_vat = 29.17; $price_inc_vat = $price_ex_vat + ($price_inc_vat * $vat_rate / 100); 

now round 2 decimal places ff:

$price_inc_vat = 29.17; $price_inc_vat = $price_ex_vat + ($price_inc_vat * $vat_rate / 100); $price_inc_vat = round($price_inc_vat, 2); 

Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -