phpeveryday.com

The best tutorial of php, php framework, php strategies, object oriented oriented,


PHP - number: Calculating Future Value

Tag: number. calculation, future value   Category: PHP Basic
post: 16 Mar 2008 read: 63


PHP Number Tips - Part 2: In order to find the future value of a sum of money, given a fixed interest rate, you have to calculate the future value by compounding the sum over periods using the supplied interest rate such as the following:

<?php
//define present value
$presentValue = 100000;

//define interest rate per compounding period
$intRate = 8;

//define number of compounding periods
$numPeriods = 6;

//calculate future value assuming compound interest
//result: "100000 @ 8 % over 6 periods becomes 158687.43"
$futureValue = round($presentValue * pow(1 + ($intRate/100),↵
$numPeriods), 2);
echo "$presentValue @ $intRate % over $numPeriods periods becomes ↵
$futureValue";
?>

The formula to calculate the future value (F) of a particular amount (P), given a fixed interest rate ( r ) and a fixed number of years ( n ), is F = P(1 + r/100)n. Nevertheless, you will be surprised how many novice programmers forget all about PHP's operator precedence rule. Then, for the result, they generate incorrect results.




| Give Your Opinion | Recommend
Share and Bookmark to: These icons link to social bookmarking sites where readers can share and discover new web pages.
digg del.icio.us technorati Ma.gnolia BlinkList

Recommended articles by other readers:
Web Services: How PHP Kiss VB.NET? (Part 1)
Chart: How to Build Cool Animation Real Time Chart
Joomla: Fast Road to Understand Component Programming
Email: Send Attachement Mail
mod_rewrite - Part 1: create your "fantasy" URL

What do You Think?
Your Name *:
Email *:
(Will not be published)
Website/URL:
Your Comment *:
* Required


615
posting