Home > Back-end >  Calculating TAX in PHP and displaying correct
Calculating TAX in PHP and displaying correct

Time:01-23

need help with tax calculation displaying

tax cal code

$vat = 7.75;
$taxesOnly = ($val['quantity'] * $val['price'] / 100) * $vat;

result: $51.925

what i want: $51.92

thank you in advance

CodePudding user response:

you can use round($taksesOnly) like this code

$val = array(
             'quantity' => 1,
             'price' => 50
            ); 
$vat = 7.75;
$taxesOnly = ($val['quantity'] *$val['price'] / 100) * $vat;
echo round($taxesOnly,2);

CodePudding user response:

$vat = 7.75;
$taxesOnly = ($val['quantity'] * $val['price'] / 100) * $vat;
return number_format($taxedOnly,2,'.',',');

this will return you two digit of decimal , or if you want to make changes accordingly based on currency & decimal separators.

  •  Tags:  
  • php
  • Related