For Programmers: Free Programming Magazines  


Home > Archive > AWK > April 2006 > begginer printf problem









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author begginer printf problem
tomv5001@hotmail.com

2006-04-04, 6:56 pm

Hello: I have what I think should be a simple problem regarding printf.


Given the following line I need to add the letter "M" to the output but
I want it to be right next to the number.. in other words this:

{ printf "%-12.1fM", 15946980/1000000 } =>outputs => "15.9 M"

I need this "15.9M "

how can I do this ?

Juergen Kahrs

2006-04-04, 6:56 pm

tomv5001@hotmail.com wrote:

> Given the following line I need to add the letter "M" to the output but
> I want it to be right next to the number.. in other words this:
>
> { printf "%-12.1fM", 15946980/1000000 } =>outputs => "15.9 M"


The - here ^ should be removed. It causes
the output to be left aligned.
Harlan Grove

2006-04-04, 6:56 pm

Juergen Kahrs wrote...
>tomv5001@hotmail.com wrote:
>
>The - here ^ should be removed. It causes
>the output to be left aligned.


Too much snippage. The OP continued,
[color=darkred]

Just removing the - from the printf call above produces "
15.9M". If the OP really does want a left-aligned result, then it
requires something like

printf "%-12s", sprintf("%.1fM", 15946980/1000000)

tomv5001@hotmail.com

2006-04-05, 6:56 pm

thank you .. thats exactlly what I needed

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com