Anonymous user
Determine if a string is numeric: Difference between revisions
→{{header|COBOL}}: Split into sections and corrected grammar.
m (→{{header|Déjà Vu}}: Updates example) |
(→{{header|COBOL}}: Split into sections and corrected grammar.) |
||
Line 403:
=={{header|COBOL}}==
===Intrinsic Functions===
COBOL has the intrinsic functions <code>TEST-NUMVAL</code> and <code>TEST-NUMVAL-C</code> to check if a string is numeric (<code>TEST-NUMVAL-C</code> is used to check if it is also a monetary string). Implementations supporting the 20XX draft standard can also use <code>TEST-NUMVAL-F</code> for floating-point numbers. They return 0 if the string is valid, or the position of the first incorrect character.
<lang cobol> program-id. is-numeric.▼
procedure division.▼
display function test-numval-f("abc") end-display▼
display function test-numval-f("-123.01E+3") end-display▼
if function test-numval-f("+123.123") equal zero then▼
display "is numeric" end-display▼
else▼
display "failed numval-f test" end-display▼
end-if▼
goback.</lang>▼
===Implementation===
{{works with|OpenCOBOL}}
<lang cobol> IDENTIFICATION DIVISION.
Line 458 ⟶ 473:
GOBACK
.</lang>
▲<lang cobol> program-id. is-numeric.
▲ procedure division.
▲ display function test-numval-f("abc") end-display
▲ display function test-numval-f("-123.01E+3") end-display
▲ if function test-numval-f("+123.123") equal zero then
▲ display "is numeric" end-display
▲ else
▲ display "failed numval-f test" end-display
▲ end-if
▲ goback.</lang>
=={{header|CoffeeScript}}==
|