From: | Vic E Babes |
Date: | 19 Sep 99 at 13:54:25 |
Subject: | Re: Rounding amounts |
> > Hmm, I don't know about elegant, but I'd probably do something like
this:
>
> > THat should do what you want... I think. :) Let me know if it's full
of
> > holes, and nasty bugs!
>
> That was much better than what I was trying to do!
>
> Here's a cleaned-up, function-ised version (note that it rounds specific
> to Tony's requirements)...
>
I have a solution, but as always, there is one slight thing that spoils its
elegance. Note that the UNITS that should round to 10 have bit 3 set - the
UNITS that should round to 5 have bit 2 set, and the UNITS that should round
to 0 have neither set.
1 0001
2 0010
3 0011 *problem here
---------------
4 0100
5 0101
6 0110
7 0111
------------------
8 1000
9 1001
The slight snag is that 3 doesn`t follow these rules, so you have to account
for it as follows:
tcents=(cents / 10) * 10 ; lose the decimal UNITS
cents-tcents
IF cents=3
cents=tcents + 5
ELSE
cents=tcents + ((cents LSR 2) * 5
ENDIF
Please note that I`ve typed this in Outlook Express on my parents PC, so
can`t test it `till I get home - but it looks okay to me.
VIC E BABES
---------------------------------------------------------------------
To unsubscribe, e-mail: blitz-list-unsubscribe@netsoc.ucd.ie
For additional commands, e-mail: blitz-list-help@netsoc.ucd.ie