|
Posted by Jerry Stuckle on 02/10/07 14:06
Martien van Wanrooij wrote:
> I am working on some financial calculators and although I succeeded to
> created the required formulas I am not sure about the following.To give
> an example: when somebody puts a capital on the bank with a yearly
> interest of x % , the final capital after, say, 30 years can easily be
> calculated. Since I want to be able to show the capital created after
> every year I prefer to do it with a loop, something like
> for($x= 1; $x < 30; $x++){
> $capital = $capital*(1 + $interest /100)
> } .
> Another reason for such a loop is that the visitor could tell that he
> want to withdraw some capital in the so-manieth year
> Now let's say the visitor of the page can do a "quick scan" (just
> showing the final amount) and request a table with all the yearly
> amounts afterwards. In this case I will either have to store all the
> yearly capital values into a an array and register that array to a
> session, or I will need to do the whole loop again but this time
> something like
> $capital = $capital*(1+ $interest/100);
> echo "<tr><td>$capital</td></tr>";
> Although the formulas I "translated" from several excel sheets work
> fine, I would like to know if storing such arrays could have negative
> consequences for performance or memory on the server
> Alternative suggestions, of course are also welcome. I tried to find
> similar scripts on Google but I wasn't very successfull, probably
> because I am not very familiar with the English financial terms
>
> Thanks for any help.
>
> Martien.
>
>
>
Martien,
Programming is all about tradeoffs. Often time the tradeoff is between
memory and cpu utilization.
Would storing arrays have negative consequences? Sure. But so would
calculating the figures every time.
Which is better? It's impossible to tell. It all depends on your
server, your users (both number and frequency) and probably a dozen
other things.
You need to figure out how much data you're talking about and how often
it's being requested. That will help you determine which is the better
way to go.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Navigation:
[Reply to this message]
|