Determine if a string is numeric: Difference between revisions
Content deleted Content added
Determine if a string is numeric en True BASIC |
m →{{header|REXX}}: added a few more examples, changed comments and glyphs. |
||
Line 3,584: | Line 3,584: | ||
=={{header|REXX}}== |
=={{header|REXX}}== |
||
<lang rexx>/*REXX program |
<lang rexx>/*REXX program determines if a string is numeric, using REXX's rules for numbers. */ |
||
yyy=' -123.78' /*or some such.*/ |
yyy=' -123.78' /*or some such. */ |
||
/*strings below are all numeric (REXX).*/ |
/*strings below are all numeric (REXX).*/ |
||
zzz= |
zzz= ' -123.78 ' |
||
zzz='-123.78' |
zzz= '-123.78' |
||
zzz='2' |
zzz= '2' |
||
zzz="2" |
zzz= "2" |
||
zzz=2 |
zzz= 2 |
||
zzz='000000000004' |
zzz= '000000000004' |
||
zzz='+5' |
zzz= '+5' |
||
zzz= |
zzz= +5 |
||
zzz=' |
zzz= ' +6 ' |
||
zzz=' |
zzz= ' + 7 ' |
||
zzz=' |
zzz= ' - 8 ' |
||
zzz=' |
zzz= ' - .9' |
||
zzz='. |
zzz= '- 19.' |
||
zzz=' |
zzz= '.7' |
||
zzz= |
zzz= .7 |
||
zzz=' |
zzz= '2e3' |
||
zzz= |
zzz= 47e567 |
||
zzz=' |
zzz= '2e-3' |
||
zzz=' |
zzz= '1.2e1' |
||
zzz=' |
zzz= ' .2E6' |
||
zzz=' |
zzz= ' 2.e5 ' |
||
zzz=' + |
zzz= ' +1.2E0002 ' |
||
zzz=' |
zzz= ' +1.2e+002 ' |
||
zzz=' |
zzz= ' +0000001.200e+002 ' |
||
zzz= ' - 000001.200e+002 ' |
|||
ifx=i |
|||
zzz= ' - 000008.201e-00000000000000002 ' |
|||
/*Note: some REXX interpreters allow use of tab chars as blanks. */ |
/*Note: some REXX interpreters allow use of tab chars as blanks. */ |
||
/*all statements below are equivalent.*/ |
|||
if \datatype(yyy,'n') then say 'oops, not numeric:' yyy |
if \datatype(yyy, 'n') then say 'oops, not numeric:' yyy |
||
if \datatype(yyy,'N') then say 'oops, not numeric:' yyy |
if \datatype(yyy, 'N') then say 'oops, not numeric:' yyy |
||
if ¬datatype(yyy,'N') then say 'oops, not numeric:' yyy |
if ¬datatype(yyy, 'N') then say 'oops, not numeric:' yyy |
||
if ¬datatype(yyy,'numeric') then say 'oops, not numeric:' yyy |
if ¬datatype(yyy, 'numeric') then say 'oops, not numeric:' yyy |
||
if ¬datatype(yyy,' |
if ¬datatype(yyy, 'nimrod.') then say 'oops, not numeric:' yyy |
||
if datatype(yyy)\=='NUM' then say 'oops, not numeric:' yyy |
if datatype(yyy) \== 'NUM' then say 'oops, not numeric:' yyy |
||
if datatype(yyy)/=='NUM' then say 'oops, not numeric:' yyy |
if datatype(yyy) /== 'NUM' then say 'oops, not numeric:' yyy |
||
if datatype(yyy)¬=='NUM' then say 'oops, not numeric:' yyy |
if datatype(yyy) ¬== 'NUM' then say 'oops, not numeric:' yyy |
||
if datatype(yyy)¬= 'NUM' then say 'oops, not numeric:' yyy |
if datatype(yyy) ¬= 'NUM' then say 'oops, not numeric:' yyy |
||
/*note: REXX only looks at the first char for DATATYPE's 2nd |
/*note: REXX only looks at the first char for DATATYPE's 2nd argument.*/ |
||
/*note: some REXX interpreters don't support the ¬ (not) character.*/ |
/*note: some REXX interpreters don't support the ¬ (not) character. */</lang> |
||
/*note: " " " " " the / as negation. */</lang> |
|||
=={{header|Ring}}== |
=={{header|Ring}}== |