Re: printf: zero pad after the decimal a given amount



Paul Lalli wrote:
On Mar 30, 4:09 pm, jida...@xxxxxxxxxxx wrote:
Why is there no way to tell printf to zero pad like the right column:

Why do you assume that because you don't know the way, there is no
way?

0.1 :0.100
0.05 :0.050
0.03 :0.030
0.025 :0.025
0.02 :0.020
0.015 :0.015
0.0125 :0.0125
0.01 :0.010
0.009 :0.009
0.00625:0.00625
0.005 :0.005
The challenge: Change only the "WHAT?" below to produce the right
column above. Thanks.
use constant S => 100000;
for ( 10000, 5000, 3000, 2500, 2000, 1500, 1250, 1000, 900, 625, 500
) { printf "%-7g:WHAT?\n", $_ / S, $_ / S;


%.03f

$ perl -e'printf("%.03f\n", .1)'
0.100

Paul Lalli

Actually that truncates to 3 decimal places, which isn't what the op
required:

$ perl -e'printf("%.03f\n", .00625)'
0.006


See my other post for a working solution.

--
szr


.



Relevant Pages

  • Re: Cant get group to match - please help
    ... >> Paul Lalli wrote: ... >>> It requires neither greatness nor wisdom to read the posting guidelines ... > Meaning that you found this newsgroup, and decided to dig right in and ... Actually I did do a search in the three perl reference books I have ...
    (comp.lang.perl.misc)
  • Re: OT: spelling, grammar, and capitalization. [was: Re: perl e-books]
    ... Paul Lalli wrote: ... However, as you should know, I'm a new perl user. ... Can you, or anyone else out there who writes like hisam here, please ... When I see writing like the top of this posting, ...
    (perl.beginners)
  • Re: Sample perl code does not work (from Perl cookbook, 2nd ed.)
    ... Paul Lalli wrote: ... >> Could someone explain a perl wanabee why this code fragment does not ... >> perl installed. ... Staale Flock ...
    (comp.lang.perl.misc)
  • Re: open for pipe problem
    ... Paul Lalli wrote: ... > Brian meant that your coding style is much more consistent with the ... > lines that contain the first instance of each possible first field ... > This can be fairly straightforwardly converted to Perl: ...
    (comp.lang.perl.misc)
  • Re: Perl and modems
    ... "Paul Lalli" wrote in message ... >> I want to write a script that will send information to the modem to ... I heard that this>> can be done in perl but I am net to perl. ... > If you are comfortable with the language, I point you to CPAN. ...
    (comp.lang.perl.misc)