RosettaCodeData/Task/Determine-if-a-string-is-numeric/Free-Pascal/determine-if-a-string-is-numeric.free
2019-09-12 10:33:56 -07:00

18 lines
571 B
Text

function isNumeric(const potentialNumeric: string): boolean;
var
potentialInteger: integer;
potentialReal: real;
integerError: integer;
realError: integer;
begin
integerError := 0;
realError := 0;
// system.val attempts to convert numerical value representations.
// It accepts all notations as they are accepted by the language,
// as well as the '0x' (or '0X') prefix for hexadecimal values.
val(potentialNumeric, potentialInteger, integerError);
val(potentialNumeric, potentialReal, realError);
isNumeric := (integerError = 0) or (realError = 0);
end;