Thanks, Adam!
It solved my problem!
Regards,
Rodrigo
--- In geeksthatgawk@yahoogroups.com, "Adam" <onzanews@e...> wrote:
> hello Rodrigo,
> try
> $ awk 'BEGIN{ print sprintf("%05d, %06.2f", 23, 4.5) }'
> 00023, 004.50
>
> the '6' in "%06.2f" is the minimum width of the outputed float.
> (including the decimal point and the fraction part.)
> EG:
> $ awk 'BEGIN{ print length(sprintf("%06.2f", 4.5)) }'
> 6
>
> the 2 in "%06.2f" is the minimum width of the fraction part.
> EGs:
> pattern output
> "%06.2f" 004.50
> "%06.3f" 04.500
> "%06.4f" 4.5000
> "%06.5f" 4.50000
> "%06.6f" 4.500000
>
> hope this helps
> +m
> za (Adam Onza)
>
> --- In geeksthatgawk@yahoogroups.com, "Rodrigo Hjort"
> <rodrigo_hjort@y...> wrote:
> > Hi, AWK users!
> >
> > When using sprintf() to format float numbers with left padding zeroes,
> > it doesn't work. For example, the output desired below should be
> > "00023, 004.50".
> >
> > $ awk 'BEGIN{ print sprintf("%05d, %03.2f", 23, 4.5) }'
> > 00023, 4.50
> >
> > Does anyone ever had this problem? Should this be an AWK bug?
> > These codes were performed on mawk version 1.3.3-11.
> >
> > Best regards,
> >
> > Rodrigo Hjort
> >
> > http://rhjort.cjb.net/
> >
> > Linux User #348191 (http://counter.li.org)