Or this?
for i=0 to 9
print Formatted_number(10^i)
next i
print Formatted_number(1234567890)
wait key
end
function Formatted_Number(n)
fs$=""
sn$=str$(n)
sl=len(sn$)
for i=1 to sl step 3
fs$=right$(sn$,3)+left$(",",(i<>1))+fs$
sn$=left$(sn$,len(sn$)-3)
next i
` this is to fix negative numbers with a leading comma
if left$(fs$,2)="-,"
fs$="-"+right$(fs$,len(fs$)-2)
endif
endfunction fs$
Different codeing style, maybe.
Edit: I think I had an un-needed test. (removed it)
Another edit: I couldn't get to sleep, so:
And another edit: Corrections made for negative numbers. Same type of correction needed in the snippets from AndrewT and IanM.
rem recursive comma formater
rem
` test full numbers
for i=9 to 0 step -1
num=1234567890/(10^i)
print Comma(num)
next i
` test leading zeros
for i=0 to 9
num=1001001001/(10^i)
print Comma(num)
next i
` test zero fill and negative numbers
for i=0 to 9
print Comma(-1*10^i)
next i
wait key
end
function Comma(n)
sn=n/abs(n*(n<>0)+(n=0))
n=sn*n
if n>999
r=n mod 1000
l=sn*n /1000
f$=Comma(l)+","+right$("00",1*(r<10)+1*(r<100))+str$(r)
else
f$=left$("-",(sn<0))+str$(n)
endif
endfunction f$
Whatever...