This function is used to examine an argument supplied as a string and returns its numeric value. If the string supplied begins with a leading 0, it is treated as an octal number. If the string begins with a leading 0x, it is treated as a hexadecimal number. The following example illustrates the working strtonum() function:
$ vi strtonum.awk
BEGIN {
print "Decimal num strtonum(123) : ", strtonum(123)
print "Octal num strtonum(0123) : ", strtonum(0123)
print "Hexadecimal num strtonum(0x123) : ", strtonum(0x123)
}
$ awk -f strtonum.awk
The output of the execution of the previous code is as follows:
Decimal num strtonum(123) : 123
Octal num strtonum(0123) : 83
Hexadecimal num strtonum(0x123) : 291
Apart from the preceding function, we have asort (sring,[a]) and asorti(string, [a]), which are available only in GAWK and which we will ;discuss in Chapter 9, GNU's Implementation of AWK - GAWK (GNU AWK).