Determine if a string is numeric: Difference between revisions

Content added Content deleted
(Added Commodore BASIC.)
Line 888: Line 888:
ready.
ready.
&#9608;</pre>
&#9608;</pre>
==={{header|QB64}}===
<lang QB64>
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
</lang>
{{out}}
<pre>
Enter a text or a number: 12345
You entered a number.

Enter a text or a number: Four
You did not enter a number.

Enter a text or a number: 99, rue de Rivoli
You did not enter a number.

Enter a text or a number: 9E4
You entered a number.</pre>
NB: While "99, rue de Rivoli" contains a number it is not a number entirely. The Val(v$) in this case would have stopped after it converted the "99" portion of the input, which when converted back to a string and compared to the original input would not result in an equality. 9E4 the program reads as an exponential value.


=={{header|Batch File}}==
=={{header|Batch File}}==