XP arithmetic

John Ridge ridge11103 at btinternet.com
Sun Jun 26 05:01:55 EDT 2005


I've just hit something that seems to me very weird. I'd appreciate any
thoughts. 

The (tiny) problem is to calculate the interest due on a sum of common-law
compensation - our client X paid certain sums over a period; the court has
now agreed that they should not have been required to pay. OK, they get the
money back - plus interest at R%. This represents the interest they would
have earned if each payment had, at the time it was made, gone into a
high-interest savings account. My first thought was that this was a future
value calculation, so I used Excel - but I couldn't get sensible answers.
Fine - write a tiny stack to do it iteratively.

While I was at it, I allowed for daily, weekly or monthly (28-day lunar)
compounding periods (shouldn't really make much difference). I then display
the amount of interest, and the effective annual interest rate R*. This is
just the percentage increase of the basic compensation award, adjusted for
the length of time - so we multiply by, for example (365 / <number of days>)
- if the period is more than a year, this deflates the percentage increase
to the effective annual rate and vice versa.

The relevant bit of script is as follows:-

set the numberFormat to "0.00"
put "£" & (tCumInterest - tTotalAmount) into fld "InterestDue"
put "£" & tCumInterest into fld "TotalAmount"
put ((tCumInterest - tTotalAmount)/tTotalAmount) * 100 into tAnnRate
if "Daily" is in gPeriod then put tAnnRate * 365/tDays into tAnnRate
if "Weekly" is in gPeriod then put tAnnRate * 52/tDays into tAnnRate
if "Monthly" is in gPeriod then put tAnnRate * 13/tDays into tAnnRate
put tAnnRate & "%" into fld "OverallRate"
-- I apologise for tdays - it is really "number of compounding periods"

This works perfectly on a G4 Mac OS 9.3. I decided that it might be a useful
gadget for people in the office, so I made a standalone for XP. That doesn't
work - the effective interest rate is not adjusted for length of the period.
This is not a problem with the pop-up menu - the XP version knows elsewhere
whether it is doing a daily, weekly or monthly calculation. The percentage
increase tAnnRate is correct. Somehow the expressions "365/tDays" etc are
evaluating to 1. But only in the XP standalone...

Sorry to have gone on at such length, but I've had trouble believing what
I'm seeing here. If anyone is interested, I'm sharing the stack in user area
"jmr" as "Interest"


-- 





More information about the use-livecode mailing list