Determine if a string is numeric: Difference between revisions

no edit summary
No edit summary
Line 655:
disp(isnum("3.1415")) % 1</lang>
 
 
=={{header|Pascal}}==
<lang pascal>
function IsNumeric(Value: string; const AllowFloat: Boolean): Boolean;
var
ValueInt: Integer;
ValueFloat: Extended;
ErrCode: Integer;
begin
// Check for integer: Val only accepts integers when passed integer param
Value := SysUtils.Trim(Value);
Val(Value, ValueInt, ErrCode);
Result := ErrCode = 0; // Val sets error code 0 if OK
if not Result and AllowFloat then
begin
// Check for float: Val accepts floats when passed float param
Val(Value, ValueFloat, ErrCode);
PreventHint(ValueFloat); // prevents "value never used" hint
Result := ErrCode = 0; // Val sets error code 0 if OK
end;
end;
</lang>
 
=={{header|Perl}}==
Anonymous user