Blitz (472/640)

From:John Mason
Date:18 Sep 99 at 22:04:30
Subject:Re: Rounding amounts

Hi Tony,

> Australia has no 1 or 2 cent coins, so cash amounts are rounded to the
> nearest 5 cents.
> I have a long variable containing the number of cents and need to
> round so numbers ending in 3,4,5,6 or 7 are converted to end in 5, all
> others are to end in zero (1,2 rounded down, 8 & 9 rounded up)
> any elegant ideas anyone?

Hmm, I don't know about elegant, but I'd probably do something like this:

cents.s = str$(cents.l)
onesdigit.s=right$(cents.s,1) ; get ones digit as a single character

cents.l - val(onesdigit) ; drop to lowest nearest multiple of 10

select onesdigit
case "3" ; same for 4, 5, 6, 7 (where's C when you need it?)
cents.l + 5
case "8" ; & nine
cents.l + 10 ; round up to the next 10
case "1" ; & 2
; do nothing here
end select

-----

THat should do what you want... I think. :) Let me know if it's full of
holes, and nasty bugs!

Regards,



John Mason -- ICQ 17931257
http://chebucto.ns.ca/~ah210/Profile.html
Home of NewStuff and Reminder!

---------------------------------------------------------------------
To unsubscribe, e-mail: blitz-list-unsubscribe@netsoc.ucd.ie
For additional commands, e-mail: blitz-list-help@netsoc.ucd.ie