Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

round up digits in numbers

by newPerlr (Novice)
on Dec 05, 2008 at 07:23 UTC ( #728205=perlquestion: print w/replies, xml ) Need Help??
newPerlr has asked for the wisdom of the Perl Monks concerning the following question:

say i have numbers 1, 2, 3, 4, 5, 6,7 ,9, 10 ...
i want show this in in 5 digits something like
00001, 00002 ,.., 00010
can i do this in perl??
can i assign it back to a variable as well??? thank you in advance..

Replies are listed 'Best First'.
Re: round up digits in numbers
by moritz (Cardinal) on Dec 05, 2008 at 07:31 UTC
Re: round up digits in numbers
by quester (Vicar) on Dec 05, 2008 at 07:35 UTC
    You want the printf function.

    For example:

    #! /usr/bin/perl -w use strict; use diagnostics; my $n=42; printf "%05d\n", $n;
    See sprintf for details of the first argument to printf.
Re: round up digits in numbers
by repellent (Priest) on Jan 08, 2009 at 06:10 UTC
    my @n = ('00001' .. '00010');

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://728205]
Approved by GrandFather
help
Chatterbox?
[Discipulus]: iirc active perl has repositories only for last 2 o 3 major release of perl Mj1234. I strongly suggest portable version of strawberry perl and use cpan client to install modules
[choroba]: Also, who needs GDB when there's hdb?
[Discipulus]: in this ubuntu i'm not able to find resource monitor, graphical mount program.. just office and amazon are exposed!

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (7)
As of 2016-12-07 08:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (125 votes). Check out past polls.