Line 1020 uses this value of xy and returns the "string" up to two places to the right of the decimal point. Thus the value of xx$ will be in this formThe following article was written by Tom Keene of the Inland Empire ADAM User's Group, IEAUG, and was transcribed by VISA to their ADVISA newsletter (we appreciate their contributions). 
\\ 
\W\CALIGNING NUMBERS\\ 
IN SMARTBASIC\w\\ 
\\ 
\K\Q\A\\ 
There are a number of irritating flaws in SmartBASIC. Some are extremely serious, while others are merely aggravating. I have previously discussed the serious failing in sorting large quantities of data. ADAM, or more correctly, SmartBASIC just simply fails to execute legitimate commands that are issued. It is not because of complicated logic so much as it is an overwhelming of the system.\\ 
\\ 
The problem under discussion here has been noted by others years ago, but my experience with these observations is that they were very incomplete and sometimes erroneous. Someone had written to Coleco that they noticed a failure of SmartBASIC to yield a correct answer when dividing by 100. It was said that   it occurred in some numbers larger than 8191. Coleco issued a Tech Bulletin but offered no explanation of the cause nor did they offer any solutions. This problem crops up unexpectedly with numbers that appear to have no correlation with anything.  \\ 

\\ 
\r~45,80\\ 
\K\B\A\\ 
\\ 
\\ 
\\ 
\\ 
This can be really disconcerting when printing an output in which you would like columns of numbers to all have the decimal points line up vertically.\\ 
\\
I am reminded of the TV commercial that CANON typewriters ran several years ago. In this commercial, Marsha gets a rose from her boss (yes rose--not a raise) for changing some figures on a CANON typewriter on which EVEN THE DECIMAL POINTS LINE UP!.\\ 
\\ 
Not withstanding the Technical Bulletin, this problem will occur with many numbers much lower than 8191. Here is a little program that you can dash out that will show the effect of some undesirable displays:\\ 
\\ 
10 INPUT "Enter any number";n:PRINT n\\ 
\\ 
Now run this SmartBASIC program and enter the number 392.00.  Instead of printing 392.00, it will print 392 with no decimal point and no figures in the cents column.\\ 
\\ 
But if you enter 393.00 you are in for a greater shock. It prints out 392.999999 which makes lining up columns a real pain. I ran into this problem on a Commodore 64 (UGH!) that my brother was using and I came up with a short subroutine which corrected both the lack of a decimal point and the following zeros and the 
\L\\ 
10 INPUT "Enter any number";N:?:?:?\\ 
\\ 
(NOTE The ? question mark is shorthand for PRINT.)\\ 
\\ 
20 INPUT "enter another number";M:?:?:?\\ 
30 xx=N:GOSUB 1000:N$=xx$\\ 
40 xx=M:GOSUB 1000:M$=xx$\\ 
50 ? "Corrected Value Of N = ";N$:?\\ 
60 ? "Corrected Value Of M = ";M$:?\\ 
70 END\\ 
1000 xx=xx+1E-03: xy=1: xx$=STR$(xx): IF xx<5E-03 THEN xx$ ="0.00": GOT 1030\\ 
1010 If MID$(xx$,xy,1)<> "." THEN xy = xy+1: GOTO 1010\\ 
1020 xx$ = LEFT$(xx$,xy+2)\\ 
1030 RETURN\\ 
\A\\
I suggest that you now try those two numbers again, ---- 392.000 and 393.000. You will find that they now print correctly. Line 1000 adds a small increment to the input number and then it creates a "string" of the number xx. It then tests the real value of xx and makes a "string" = 0.00 if it is a small number,(virtually zero). Line 1010 searches for the decimal point. Notice that the GOTO statement at the end of the line sends it back to the start of the line. It continues to search until it finds the decimal point. \\

 INPUT "Enter any number";N:?:?:?\\ 
\\ 
(NOTE The ? question mark is shorthand for PRINT.)\\ 
\\ 
20 INPUT "enter another number";M:?:?:?\\ 
30 xx=N:GOSUB 1000:N$=xx$\\ 
40 xx=M:GOSUB 1000:M$=xx$\\ 
50 ? "Corrected Value of N = ";N$:? 
60 ? "Corrected Value of M = ";M$:? 
70 END 
1000 xx = xx + 1E-03:xy=1: xx$+STR$(xx): IF xx(5E-03 THEN xx$ = "0.00": GOTO 1030.  
1010 If MID$(xx$,xy,1)<>"." THEN xy = xy+1: GOTO 1010 
1020 xx$ = LEFT$(xx$,xy+2) 
1030 RETURN
I suggest that you now try those two numbers again,----392.000 and 393.000. You will find that they now print correctly.  Line 1000 adds a small increment to the input number and then it creates a "string" of the number xx. It then tests the real value of xx and makes a "string" = 0.00 if it is a small number, (virtually zero). Line 1010 searches for the decimal point. otice that the GOTO statement at the end of the line sends it back to the start of the line. It continues to search unitl it finds the decimal point. 
Line 1020 uses this value of xy and returns the "string" up to two places to the right of the decimal point. Thus the value of xx$ will be in this form---PPP.QQ. This routine can be readily included in any program where you want the output to have all of the decimal points line up vertically. If some numbers had no zeros and others had a bunch of nines, it would be almost impossible to print them in a neat column.\\ 
\\
I am including a financial program I wrote a number of years ago which will illustrate the use of the subroutine in a program. The financial program follows this article. The program accepts inputs for calculating the monthly payment for a loan when the amount of the loan, the annual interest rate and the duration of the loan are specified. After computing the monthly payment, it asks you if you would like to have the month-by-month printout of the amortization of the loan. If you choose to have the amortization printed out, it asks you if you want to use the calculated payment or any other payment you care to make 
xecuted numerous times in the operation of the program by a command GOSUB 3500 (See lines 2200, 2300, 2700, 3200, and twice in 3300). This is an example of how an effective subroutine can be repeatedly invoked in a master program.\\ 
\\ 
\W\CSMARTBASIC PROGRAM LISTING.\w\\ 
\L\\ 
100 REM FINANCE 2, 5 JULY 1985\\ 
200 REM By Thomas J. Keene,\\ 
300 REM 3141 Palmyra Avenue,\\ 
400 REM Orange, CA, USA, 92669.\\ 
500 DEF FN g(x) = (INT(1+100*x))/100\\ 
600 DEF FN f(x) = (INT(.5+100*x)/100:tp=0:ti=0:m=1\\ 
700 INPUT "Annual interest rate = ";i:PRINT 1*100; "%"\\ 
800 INPUT "Amount to be borrowed = ";a:PRINT "$";a\\ 
900 INPUT "Loan duration (years) = ";y:PRINT y; "years"\\ 
1000 r = i/12: k = (l+r)^(y*12):p = a*r*k/(k-1):PRINT:PRINT\\ 
1100 PRINT " Monthly Payment = $";:p = FN g(p):PRINT p:PRINT\\ 
1200 INPUT "Do you wish to print the amortization ,----month by month/ Answer Y/N. ";d$:PRINT " .....";d$:PRINT\\ 
1300 IF d$ = "Y" OR d$ = "y" THEN 1500\\ 
1400 PRINT "Thank You.";:END\\ 
\\ 
1500 INPUT "Do you wish to use a different monthly payment?  Answer Y/N. ";p$:PRINT " ***** ";p$:PRINT\\ 
1600 IF p$ = "N" OR p$ = "n" THEN 1800\\ 
1700 INPUT "Enter NEW monthly Payment = ";p:PRINT "$";p\\ 
1800 PRINT " "," ", "INTEREST", "PRINCIPAL"\\ 
1900 i = r*a: a = a*(l+r)-p:PRINT " ":PRINT "Ata the end of the Month ";m\\ 
2000 m = m+1: b = p-i: am = FN f(a): it = FN F(i): pri = FN f(b)\\ 
2100 e$ = STR$(INT(i)): c$ = LEFT$(e$,8): d = 37-LEN(c$): IF b < 1 THEN d = d+1\\ 
2200 xx = am: GOSUB 3500: am$ = xx$\\ 
2300 xx = it: GOSUB 3500: it$ = xx$\\ 
2400 IF a > 0 THEN GOTO 2600\\ 
2500 b = p-i=a: pri = FN f(b)\\ 
2600 e$ = STR$(INT(b)): c$ = LEFT$(e$,*): g = 20-LEN(c$): IF b < 1 THEN g = g+1\\ 
2700 xx = pri: GOSUB 3500" p$ = xx$\\ 
2800 PRINT "Amount Due = $"; it$; TAB(g); "$"; p$\\ 
2900 PRINT; TAB(d); "$"; it$; TAG(g);"$"; p$\\ 
3000 ti = ti+i: tp =tp+b\\ 
3100 If a> 0 THEN GOTO 1900\\ 
3200 PRINT "Last Payment = "; : lp = b+i: xx = FN f(lp): GOSUB 3500: PRINT xx$\\ 
3300 PRINT "Total Interest = ";: xx = FN f(ti): GOSUB 3500:  PRINT xx$: PRINT "Total Principal = ";: xx = FN f(tp): GOSUB 3500: PRINT xx$\\ 
340 END\\ 
3500 xx = xx+1E-03: xy = 1: xx$ = STR$(xx): IF xx < 5E-03 THEN xx$ = "0.00": GOTO 3800\\ 
3600 IF MID$(xx$, xy, 1) <> "." THEN xy = xy+1: GOTO 3600\\ 
3700 xx$ = LEFT$(xx$, xy+2)\\ 
3800 RETURN\A\\ 
The following is a simple SmartBASIC program which starts out with the number one, and goes to 10000 in steps of one (1,2,3,4,5,....etc) and tests each number to see if the number plus two zeros (1.00, 2.00, 3.00 etc) will be printed out as an approximation such as 392.999999 instead of 393.00. It is amazing how many numbers there are that ADAM messes up this way. This program tests for each one up to 10000. (you can increase the number by modifying LINE 200). It prints out every failure.\L\\ 
100 REM TEST OF IRRATIONAL NUMBERS.\\ 
200 FOR n = 1 TO 10000 STEP 1\\ 
300 nn = n+1E-03: mn = 1: nn$ = STR$(nn)\\ 
400 IF MID$(nn$, mn, 1) <> "." THEN mn = mn+1: GOTO 400\\ 
500 nnn$ = LEFT$(nn$, mn+2)\\ 
600 nnn = VAL(nnn$)\\ 
700 nn$ = STR$(nn): IF MID$(nn$, mn+4, 1) <> " " THEN PRINT "N = "; nnn$\\ 
800 n4 = n-nnn\\ 
900 NEXT\\ 
1000 END\\
 
