Anonymous user
Determine if a string is numeric: Difference between revisions
Determine if a string is numeric (view source)
Revision as of 18:34, 26 September 2008
, 15 years agoUndo 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'
try:
i = float(s)
except ValueError:
# not numeric
else:
# numeric
Or for positive integers only:
s = '123'
<python>def isnumeric(x): ▼
if s.isdigit():
# numeric
<python>
numeric = True
Line 442 ⟶ 453:
print '123', isnumeric('123')
print '123a', isnumeric('123a')
</python>
=={{header|Ruby}}==
|