help-gawk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to convert a string to strnum?


From: Neil R. Ormos
Subject: Re: How to convert a string to strnum?
Date: Sat, 4 Sep 2021 11:07:15 -0500 (CDT)

Peng Yu wrote:

> https://www.gnu.org/software/gawk/manual/html_node/Variable-Typing.html

> $ awk -e 'BEGIN { x="1e6"; print typeof(x), typeof(strtonum(x)) }'
> string number

> I can only convert a string to a number. But I
> don't find a way to convert a string to a
> strnum. Is there a way to do so?

shell> gawk 'BEGIN{ a="1e6"; z=match(a, /.*/, r); print "a:", typeof(a), a; 
print "r:", typeof(r[0]), r[0], r[0]*1;}'

a: string 1e6
r: strnum 1e6 1000000

Note that the answer the poster sought was in the
very section of the manual the poster himself/herself
cited:

| [...] Fields, getline input, FILENAME, ARGV
| elements, ENVIRON elements, and the elements of
| an array created by match(), split(), and
| patsplit() that are numeric strings have the
| strnum attribute. [...]



reply via email to

[Prev in Thread] Current Thread [Next in Thread]