PHP - Compound Tax In Php?
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 Similar TutorialsI tried using a for loop but I'm trying to think of a way to calculate interest for a number of years but after I have the amount of interest for one year I'm unsure of how to add the interest to the principle then calculate it again for the next year, to hold that number like $Principle + $Interest = $NewPrinciple then $NewPrinciple + $Interest for multiple years. <?php if (isset($_POST['submit'])) { $InvestmentFrequency = $_POST['InvestmentFrequency']; $CompoundFrequency = $_POST['CompoundFrequency']; $InitialInvestment = preg_replace("/[^0-9]/", '', $_POST['InitialInvestment']); $Contributions = preg_replace("/[^0-9]/", '', $_POST['Contributions']); $InvestmentLength = preg_replace("/[^0-9]/", '', $_POST['InvestmentLength']); $InterestRate = $_POST['InterestRate']; if ($InvestmentFrequency == "Weekly") { $InvestmentFrequency = "52"; } elseif ($InvestmentFrequency == "Monthly") { $InvestmentFrequency = "12"; } else { $InvestmentFrequency = "1"; } if ($CompoundFrequency == "Annually") { $CompoundFrequency = "1"; } elseif ($CompoundFrequency == "Semiannually") { $CompoundFrequency = "2"; } elseif ($CompoundFrequency == "Monthly") { $CompoundFrequency = "12"; } elseif ($CompoundFrequency == "Weekly") { $CompoundFrequency = "52"; } else { $CompoundFrequency = "365"; } if ($CompoundFrequency == "1") { $AdditionalInvestments = $Contributions * $InvestmentFrequency; $Principle = $InitialInvestment + $AdditionalInvestments; $Interest = $Principle * $InterestRate; $NewPrinciple = $Principle + $Interest; for ($x = 0; $x <= $InvestmentLength; $x++){ echo "$x - $NewPrinciple</br>"; } } } This is the output I get the principle and interest added together for the number of years I entered. Edited July 26, 2020 by dataxspy |