Formatting Numeric Input

Code snippets illustrating how LBB can be used
RNBW
Posts: 34
Joined: Thu Apr 05, 2018 9:21 pm

Re: Formatting Numeric Input

Post by RNBW » Tue Aug 28, 2018 4:52 pm

Has anyone any idea how to rectify the previous post?

Rod
Posts: 6
Joined: Fri Apr 06, 2018 7:00 am

Re: Formatting Numeric Input

Post by Rod » Wed Aug 29, 2018 10:27 am

I am not sure I am solving the actual problem but I made a small change to your function to handle -.123 it now returns -0.123

txt$=".123"
print txt$,len(txt$),num$(txt$),len(num$(txt$))
txt$="0.123"
print txt$,len(txt$),num$(txt$),len(num$(txt$))
txt$="-.123"
print txt$,len(txt$),num$(txt$),len(num$(txt$))
txt$="-0.123"
print txt$,len(txt$),num$(txt$),len(num$(txt$))
end


function num$(d$)
t = 0
for x=1 to len(d$)
a=asc(mid$(d$,x,1))
if a = 46 then t = t + 1
if (a = 46) and (t > 1) then a = 0
if a = 45 and x>1 then a = 0
if a = 46 and x = 1 then num$ = "0" + num$
'if a = 45 and mid$(num$,2,1) = "." then num$ = "-0" + num$
if a = 45 or a = 46 or a>47 and a<58 then num$=num$+chr$(a)
' chr$(46) = "."
next
a=asc(mid$(num$,1,1))
if a = 45 and mid$(num$,2,1) = "." then num$ = "-0" + mid$(num$,2) '******

end function

Post Reply