Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Re: Zero Padding to the Right of the Decimal

by KPeter0314 (Deacon)
on Jan 15, 2004 at 19:09 UTC ( [id://321638]=note: print w/replies, xml ) Need Help??


in reply to Re: Zero Padding to the Right of the Decimal
in thread Zero Padding to the Right of the Decimal

I agree whole-heartedly, the number probably shouldn't be baked into a format until you plan to display it. <insert standard disclaimer about being appropriate for the rest of your script and your coding style>

So it might look like this with only one print/printf/sprintf:

my $i=0; while ($i <=100){ $i=$i+0.01; printf("%3.2f\n",$i); }

-Kurt

Replies are listed 'Best First'.
Re: Re: Re: Zero Padding to the Right of the Decimal
by Cody Pendant (Prior) on Jan 15, 2004 at 20:40 UTC

    Just one more thing, how about this:

    printf( "%3.2f\n" , ($i + 0.01) );

    Instead of the two lines above?



    ($_='kkvvttuubbooppuuiiffssqqffssmmiibbddllffss')
    =~y~b-v~a-z~s; print
      you'll never exit the loop that way, because you never modify $i.
      You could use +=, though :
      my $i=0; while ($i <=100){ printf("%3.2f\n",$i+=0.01); }

        This thread is probably already too deep for anyone to care, but if I were doing this, I would do so thusly:

            printf "%3.2f\n", $_/100 for 0 .. 100*100;
          printf( "%3.2f\n" , ($i + 0.01)  );

      doesn't work.

      Change to:

          printf( "%3.2f\n" , ($i += 0.01)  );

      dave

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://321638]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (2)
As of 2024-04-26 03:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found