[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Applesoft Basic question



In article <3f2ct3$77k@sashimi.wwa.com> steakman@wwa.com (SteakMan) writes:
>From: steakman@wwa.com (SteakMan)
>Subject: Applesoft Basic question
>Date: 12 Jan 1995 04:58:11 GMT

>Can someone tell me why in Applesoft basic the lines:

>          10 a = 500.58
>          20 b = INT (a*100)
>          30 PRINT b

>Results in:

>          50057

>when the lines:
>          10 a = 400.58
>          20 b = INT (a*100)
>          30 PRINT b

>Results in:
>          40058
>Any help would be appreciated... BTW I'm on a ROM 01 with System 6.0
>and I'm using PRODOS BASIC 1.5

>SteakMan

>--------------------------   My Favorite Bumper   -------------------------
>| Visualise Whirled Peas |        Stickers        | Only Users Lose Drugs | 
>--------------------------steakman@sashimi.wwa.com-------------------------


	I had the same problem.  I wrote a very extensive check writing & 
inventory control system for our family business in Applesoft.  The problem 
is that some items were priced at fractions of cents per quantity (i.e., 
2.5 cents/pound).  After I would multiply the quantity by the price I would 
have to round to get the proper cents.  I avoided the rounding error by 
adding .000001 or so to the result.  However, when I tried to get back to 
dollars (x.xx) I would again see the error in dividing by 100 (.000000001 
or .99999999999 would show up).  This caused major problems in printing 
the total on checks and printing statements with limited size fields for 
each amount.
	To avoid the error I eventually decided I had to take the answer and 
build the proper price as a string, 1 digit at a time.  It took some time to 
get this working properly too since the .000000001 errors cause 
problems here also.  I think it is working properly now since I haven't 
heard of any errors in the last year.  If anyone has any more info or 
experience with this please reply.  I am interested in knowing if doing the 
INT in a separate instruction or after the multiplication will solve the 
problem.  I would also like to know if it is really predictable when such 
errors will occur (I seem to remember a problem in building the string when 
21 cents was involved- it would throw an extra zero, apparently thinking the 
total was 20 cents).  Or how to avoid this problem with the math - yea right!

Please email any reponse to: bongini@law3.law.ucla.edu

Thanks,
Steve Bongini

P.S.  If anyone would like the string building algorithm, I could probably 
dig it up.