# Calculate compound interest using pow() function in php

by anonymous

• 0
• 0
• 0
121 views
```O)rignal Source:http://codingvilla.com/calculate-compound-interest-using-pow-php-single-article-565.aspx
Compound Interest:

A compound interest is an interest that is calculated on the basis of initial principal and the combine interest of past period.

Interest:

An interest is the money that we pay for borrowing the money.

Explanation:

Suppose we borrow money from the bank on that money we pay interest. If we want to know that how much we will pay above the cost of basic amount on that money then compound interest help us to calculate that value.

Formula of compound interest:

Formula of compound interest is

A = C(1+ r/n)nt

A is the total amount that includes basic principal cost and combine past period interest after n years

c is the principal amount.

r is the interest rate(in fraction: e.g. 0.5 for 5%).

n is the no of times per year compounded.

t is the no of years invested.

Compound interest calculation in PHP:

To calculate compound interest in php first we initialize the variables then by using the compound interest formula we calculate the compound interest. For this we use pow() function of php that was built in Math function in php. It raises the first argument to the power of the second argument, and returns the result.

Code:

<? php
//declaring and initializing varialbles
\$C=5000;     //Principal amount
\$r=.0325;    //interest rate
\$n=365;      //no of times per year compounded
\$t=3;        //no of year invested
//calculation of compound interest
\$A = \$C * pow((1 + (\$r / \$n)), (\$n * \$t));
echo "Compound Interest is: ".\$A;
?>

Compound interest calculation through a function in PHP:

We can also calculate compound interest by making a php function that takes four parameters.

Code:

<? Php
function calc_compound_interest(\$a, \$r, \$f, \$y)
{
return \$a * pow((1 + (\$r / \$f)), (\$f * \$y));
}
echocalc_compound_interest(5000, .0325, 365, 3), '<br />';
?

Above is the simple php code that calculates the compound interest.

This simple article tells that how we can calculate compound interest in php.
```