Determine if a string is numeric: Difference between revisions

Undo revision 17845 by 200.102.26.6 (Talk) -Cannot handle e.g. "-123.4e-5"
(Undo revision 17845 by 200.102.26.6 (Talk) -Cannot handle e.g. "-123.4e-5")
Line 426:
 
=={{header|Python}}==
s = '123'
<python>'123'.isdigit()</python>
try:
i = float(s)
except ValueError:
# not numeric
else:
# numeric
 
Or for positive integers only:
Implementation
 
s = '123'
<python>def isnumeric(x):
if s.isdigit():
# numeric
 
<python>
<python>def isnumeric(x):
numeric = True
Line 442 ⟶ 453:
print '123', isnumeric('123')
 
print '123a', isnumeric('123a')</python>
</python>
 
=={{header|Ruby}}==
Anonymous user