format number with thousand separator

  • Follow


Right now I'm processing a file where I calculate a new field ($4) based on
the other ones.  This field is numeric and I need to format it with thousand
seprator and decimal separator. I know how to put the dec separator but not
the thousand separator.

awk -vsepcam="$SEPCAM" -vbudget="$BUDGET" -vpuntod="$PUNTOD" 'BEGIN {
   k=budget;
   FS=sepcam;
   OFS=sepcam;
  }
  {
   f3=$3
   sub( "["puntod"]", ".", f3 )
   formatted_result=sprintf("%4.3f", f3*k)
   sub("[.]", puntod, formatted_result)
   $4=formatted_result
   print
  }' $BASEPATH/regiones.conf > $TEMP_FILE

do you know how can I do that?
thanks
Matias


0
Reply woloski (3) 5/8/2004 10:28:11 PM

On 2004-05-08, Matias Woloski wrote:
> Right now I'm processing a file where I calculate a new field ($4) based on
> the other ones.  This field is numeric and I need to format it with thousand
> seprator and decimal separator. I know how to put the dec separator but not
> the thousand separator.
>
> awk -vsepcam="$SEPCAM" -vbudget="$BUDGET" -vpuntod="$PUNTOD" 'BEGIN {
>    k=budget;
>    FS=sepcam;
>    OFS=sepcam;
>   }
>   {
>    f3=$3
>    sub( "["puntod"]", ".", f3 )
>    formatted_result=sprintf("%4.3f", f3*k)
>    sub("[.]", puntod, formatted_result)
>    $4=formatted_result
>    print
>   }' $BASEPATH/regiones.conf > $TEMP_FILE
>
> do you know how can I do that?
> thanks

function commas(n) {
 n = $0 + 0
 gsub(",","",n)
 point = index(n,".") - 1
   if (point < 0) point = length(n)
   while (point > 3) {
         point -= 3
         n = substr(n,1,point)","substr(n,point + 1)
         }
   return d n
}

-- 
    Chris F.A. Johnson                  http://cfaj.freeshell.org/shell
    ===================================================================
    My code (if any) in this post is copyright 2004, Chris F.A. Johnson
    and may be copied under the terms of the GNU General Public License
0
Reply Chris 5/8/2004 10:39:04 PM


1 Replies
869 Views

(page loaded in 0.034 seconds)

Similiar Articles:













7/20/2012 7:31:44 AM


Reply: