Determine if a string is numeric: Difference between revisions

Add ed example
(Zig version added)
(Add ed example)
 
(One intermediate revision by one other user not shown)
Line 1,383:
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|SmallBASIC}}===
y = isnumber(s) returns true if s is a number or can be converted to a number.
<syntaxhighlight lang="qbasic">
a = 1.2345
b = "abc"
c = "-1.2345"
 
print isnumber(a)
print isnumber(b)
print isnumber(c)
</syntaxhighlight>
 
{{out}}
<pre>
1
0
1
</pre>
 
=={{header|Batch File}}==
Line 2,001 ⟶ 2,020:
→ YES
</syntaxhighlight>
 
=={{header|Ed}}==
 
<syntaxhighlight lang="sed">
H
g/^([-+]?[0-9]*)(\.[0-9]+([eE][+-]?[0-9]+)?)?$/s//\1\2 is numeric/
v/numeric/s/.*/& is not numeric/
,p
Q
</syntaxhighlight>
 
{{out}}
 
<pre>$ cat string-numeric.ed | ed -GlEs string-numeric.input
Newline appended
56233 is numeric
-315 is numeric
1.36 is numeric
-5.126 is numeric
3.7E-05 is numeric
1.23BC is not numeric
5.6.3 is not numeric</pre>
 
=={{header|Elixir}}==
104

edits