Search the web
Sign In
New User? Sign Up
geeksthatgawk · for GNU Awk questions & discussions
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Message search is now enhanced, find messages faster. Take it for a spin.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
Formatting Problem with sprintf()   Message List  
Reply | Forward Message #185 of 221 |
Re: Formatting Problem with sprintf()

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)








Mon Aug 29, 2005 12:52 pm

rodrigo_hjort
Offline Offline
Send Email Send Email

Forward
Message #185 of 221 |
Expand Messages Author Sort by Date

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,...
Rodrigo Hjort
rodrigo_hjort
Offline Send Email
Aug 21, 2005
5:04 pm

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. ...
Adam
adam_onza
Offline Send Email
Aug 27, 2005
6:44 pm

Thanks, Adam! It solved my problem! Regards, Rodrigo...
Rodrigo Hjort
rodrigo_hjort
Offline Send Email
Aug 29, 2005
3:45 pm
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help