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

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

awk large number output format (was: (no subject) )


From: Bob Proulx
Subject: awk large number output format (was: (no subject) )
Date: Wed, 22 Oct 2008 08:56:23 -0600
User-agent: Mutt/1.5.13 (2006-08-11)

paresh doshi wrote:
> using awk (on SCO Unix)  i tried to take a summary of a datafile
> the code used is:
> awk '
> FILENAME == "FLN" {balance[substr($0,14,3)] += substr($0,17,13) {
> END {for ( name in balance )  printf("%013s %3s of %8s\n",
> balance[name]/100,name,dt) | "sort" } ' fln
>  
> THE result i get is not proper.  Where the amounts are large,
> it displays total in some odd fashion.
>  
> Can u please see where I am making mistake.

Providing both a small test case that recreates the problem and also
showing us the output that is the problem is usually necessary in
order to understand it.  Otherwise it is very hard to guess correctly.

Is the problem something like this?  (On a 32-bit machine.)

  $ echo 123456789987654321 | awk '{printf "%s\n", $1 + 1}'
  1.23457e+17

  $ echo 123456789987654321 | awk '{printf "%.6g\n", $1 + 1}'
  1.23457e+17

If so then that is because the default output format for numbers is
"%.6g" by default and that uses exponent notation for large exponents.
Using an explicit format tailored for your needs may be your solution,
if this is your problem, I am just guessing here.

  $ echo 123456789987654321 | awk '{printf "%d\n", $1 + 1}'
  123456789987654320

Bob





reply via email to

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