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



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
.