bug-gnu-utils
[Top][All Lists]
Advanced

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

Re: gawk string to number (bug?)


From: John Cowan
Subject: Re: gawk string to number (bug?)
Date: Thu, 10 Dec 2009 13:18:41 -0500
User-agent: Mutt/1.5.13 (2006-08-11)

Valerio, Danilo scripsit:
> Dear all,
> 
> can someone help me to solve this?
> 
> :~$ echo "3671014434790262159" | awk '{print $1}'
> 3671014434790262159

The value of $1 is a string, so you are just asking print to output
that string.

> :~$ echo "3671014434790262159" | awk '{print $1+0}'
> 3671014434790262272

In this case, you are forcing the value of $1 to be a number.
Unfortunately, the number you asked for is too big to fit into an IEEE
double value, so you get an approximation.  The range of integers that
awk can handle correctly (on stock hardware) is plus or minus 2^53,
or 9007199254740992.

If you need to manipulate numbers larger than that, you can use bc.

-- 
Long-short-short, long-short-short / Dactyls in dimeter,     John Cowan
Verse form with choriambs / (Masculine rhyme):           address@hidden
One sentence (two stanzas) / Hexasyllabically
Challenges poets who / Don't have the time.     --robison who's at texas dot net




reply via email to

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