aboutsummaryrefslogtreecommitdiffstats
path: root/doc/gawktexi.in
diff options
context:
space:
mode:
Diffstat (limited to 'doc/gawktexi.in')
-rw-r--r--doc/gawktexi.in32
1 files changed, 32 insertions, 0 deletions
diff --git a/doc/gawktexi.in b/doc/gawktexi.in
index 37ecbc9f..81a24079 100644
--- a/doc/gawktexi.in
+++ b/doc/gawktexi.in
@@ -803,6 +803,8 @@ particular records in a file and perform operations upon them.
once.
* Shell Quoting:: A function to quote strings for the
shell.
+* Isnumeric Function:: A function to test whether a value
+ is numeric.
* Data File Management:: Functions for managing command-line
data files.
* Filetrans Function:: A function for handling data file
@@ -21374,6 +21376,7 @@ programming use.
* Getlocaltime Function:: A function to get formatted times.
* Readfile Function:: A function to read an entire file at once.
* Shell Quoting:: A function to quote strings for the shell.
+* Isnumeric Function:: A function to test whether a value is numeric.
@end menu
@node Strtonum Function
@@ -22164,6 +22167,35 @@ function shell_quote(s, # parameter
@c endfile
@end example
+@node Isnumeric Function
+@subsection Checking whether a value is numeric
+
+A frequent programming question is how to ascertain whether a value is numeric.
+This can be solved by using this example function @code{isnumeric()}, which
+employs the trick of converting a string value to user input by using the
+@code{split()} function:
+
+@cindex @code{isnumeric()} user-defined function
+@cindex user-defined @subentry function @subentry @code{isnumeric()}
+@example
+@c file eg/lib/isnumeric.awk
+# isnumeric --- check whether a value is numeric
+
+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
+ @}
+@}
+@c endfile
+@end example
+
@node Data File Management
@section @value{DDF} Management