Jump to content

compound tax in php?


techker

Recommended Posts

hey guys can i get some help in putting this in php ?

 

i need to calculate taxes but in quebec...so 2 taxes 

 

exapl

SUBTOTAL 3.99
TAX1: 18%
TAX2: 15%

Calculating when Compound tax is enabled:

Amount with Compound tax = (SUBTOTAL + TAX1) + TAX2

in digits:

(SUBTOTAL + TAX1) = 3.99 + 18% = 3.99 + 3.99 / 100 * 18 = 3.99 * 1.18 = 4.7082
(SUBTOTAL + TAX1) + TAX2 = 4.7082 + 15% = 4.7082 + 4.7082 / 100 * 15 = 4.7082 + 0.70623 = 4.7082 * 1.15 = 5.41443
Amount with Compound tax = 5.41443

 

Link to comment
https://forums.phpfreaks.com/topic/290248-compound-tax-in-php/
Share on other sites

You already have the math worked out for applying the taxes (highlighted below)

 

 

(SUBTOTAL + TAX1) = 3.99 + 18% = 3.99 + 3.99 / 100 * 18 = 3.99 * 1.18 = 4.7082
(SUBTOTAL + TAX1) + TAX2 = 4.7082 + 15% = 4.7082 + 4.7082 / 100 * 15 = 4.7082 + 0.70623 = 4.7082 * 1.15 = 5.41443

 

The number in purple is the subtotal you're applying tax to. The green number is the subtotal with 1st tax. The number in blue will be sales price (subtotal, 1st and 2nd taxes added together). 

 

So what is the problem. Are you unsure how covert it to PHP? All that is needed is for you to change the purple and green numbers to PHP variables.

Link to comment
https://forums.phpfreaks.com/topic/290248-compound-tax-in-php/#findComment-1486744
Share on other sites

i got it going with this

 

$TAX1=5.00;$TAX2 =9.974;///this is suppose to be 9.975 but i get a penny more..so i doped it a penny and im ok..
 $price1 = ($price * $TAX1/100) ;$price2 = ($price * $TAX2/100) ;$price3 =  $price + $price1 + $price2; $total1= round($price1, 2);$total2= round($price2, 2);$total= round($price3, 2);
Link to comment
https://forums.phpfreaks.com/topic/290248-compound-tax-in-php/#findComment-1486810
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.