RosettaCodeData/Task/Determine-if-a-string-is-nu.../Run-BASIC/determine-if-a-string-is-nu...

25 lines
526 B
Plaintext

print isNumeric("123")
print isNumeric("1ab")
' ------------------------
' Numeric Check
' 0 = bad
' 1 = good
' ------------------------
FUNCTION isNumeric(f$)
isNumeric = 1
f$ = trim$(f$)
if left$(f$,1) = "-" or left$(f$,1) = "+" then f$ = mid$(f$,2)
for i = 1 to len(f$)
d$ = mid$(f$,i,1)
if d$ = "," then goto [nxtDigit]
if d$ = "." then
if dot$ = "." then isNumeric = 0
dot$ = "."
goto [nxtDigit]
end if
if (d$ < "0") or (d$ > "9") then isNumeric = 0
[nxtDigit]
next i
END FUNCTION