|
|
format number with thousand separator
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: format number with thousand separator - comp.lang.awkRight 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 ... sed - add thousand separator - comp.unix.shellHi Guys, I have a small task, that needs to be done. I what to format a number with sed or awk to a number with thousand separators. But only if the ... Date differences in nawk - comp.lang.awkformat number with thousand separator - comp.lang.awk Date differences in nawk - comp.lang.awk format number with thousand separator - comp.lang.awk Date differences in ... set format of decimal point global? - comp.soft-sys.matlab ...format number with thousand separator - comp.lang.awk set format of decimal point global? - comp.soft-sys.matlab ... format number with thousand separator - comp.lang.awk ... Data with "," and field sepeator is ",", How to handle this - comp ...format number with thousand separator - comp.lang.awk Data with "," and field sepeator is ",", How to handle this - comp ... format number with thousand separator - comp ... removing given field and field separator - comp.lang.awk ...format number with thousand separator - comp.lang.awk removing given field and field separator - comp.lang.awk ... Remove Decmial Point in Amount - comp.lang.rexx removing ... about fraction format in dimension style - comp.cad.autocad ...format number with thousand separator - comp.lang.awk about fraction format in dimension style - comp.cad.autocad ... Run a script to convert the number to text, format it ... Remove Decmial Point in Amount - comp.lang.rexxformat number with thousand separator - comp.lang.awk Remove Decmial Point in Amount - comp.lang.rexx removing given field and field separator - comp.lang.awk ... I have a isNumeric function to check a text field is numeric .. I ...format number with thousand separator - comp.lang.awk... now I'm processing a file where I calculate a new field ($4) based on the other ones. extract last 4 numbers from zip code - comp.soft-sys.stat.spss ...format number with thousand separator - comp.lang.awk extract last 4 numbers from zip code - comp.soft-sys.stat.spss ... format number with thousand separator - comp.lang ... PEP 378 -- Format Specifier for Thousands SeparatorMotivation. Provide a simple, non-locale aware way to format a number with a thousands separator. Adding thousands separators is one of the simplest ways to humanize ... Format number with Thousands separator? 10000 --> 10,000I would like to select a BIGINT type and get a formatted result with commas. Anyone have ideas? declare @i bigint set @i = 123456789 select @i --Would like ... 7/20/2012 7:31:44 AM
|
|
|
|
|
|
|
|
|