RosettaCodeData/Task/Determine-if-a-string-is-numeric/QB64/determine-if-a-string-is-numeric.qb64
2023-07-01 13:44:08 -04:00

15 lines
1.2 KiB
Text

Input "Enter a text or a number: ", v$ 'The "$" establishes that this is a string variable. So whatever entered will be stored as
'a string.
If v$ = Str$(Val(v$)) Then 'Str$() converts numeric values to their string counter parts and Val() does the opposite,
'converting strings to their numerical values. By converting the value of whatever is stored
'in v$ to a number and then back to a string it will have either stayed completely the same,
'in which case it is a numeric value (including exponent and hex and oct based numbers) or
'what is returned by the nested Str$() and Val$() functions will be different, in which case
'one, the other, or both returned an error or a truncation of the original string which began
'with numeric characters but was not entirely a number, such as "99, rue de Rivoli".
Print "Your entered a number."
Else
Print "You did not enter a number."
End If
Sleep
System