diff options
Diffstat (limited to 'awklib/eg/lib/isnumeric.awk')
-rw-r--r-- | awklib/eg/lib/isnumeric.awk | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/awklib/eg/lib/isnumeric.awk b/awklib/eg/lib/isnumeric.awk index 6309e76a..c2699022 100644 --- a/awklib/eg/lib/isnumeric.awk +++ b/awklib/eg/lib/isnumeric.awk @@ -2,13 +2,18 @@ function isnumeric(x, f) { - switch (typeof(x)) { - case "strnum": - case "number": - return 1 - case "string": - return (split(x, f, " ") == 1) && (typeof(f[1]) == "strnum") - default: - return 0 - } + switch (typeof(x)) { + case "strnum": + case "number": + return 1 + case "string": + return (split(x, f, " ") == 1) && (typeof(f[1]) == "strnum") + default: + return 0 + } } + +Please note that leading or trailing white space is disregarded in deciding +whether a value is numeric or not, so if it matters to you, you may want +to add an additional check for that. + |