Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

help needed in printing the numbers

by singam (Initiate)
on Apr 05, 2006 at 09:20 UTC ( #541308=perlquestion: print w/replies, xml ) Need Help??

singam has asked for the wisdom of the Perl Monks concerning the following question:

hai monks,
i want to print only from 0 to 999.
if it is 0 it should print 000
if it is 12 it should print 012
if it is 2 it should print 002
the numbers may be anything between 0 to 999.But front spaces should be padded with zero or zeros

Edit: g0n - removed code tags bracketing entire post

Replies are listed 'Best First'.
Re: help needed in printing the numbers
by Corion (Pope) on Apr 05, 2006 at 09:23 UTC

    perldoc -q pad points out the sprintf function:

    my $padded = sprintf "%03s", $number;
Re: help needed in printing the numbers
by murugu (Curate) on Apr 05, 2006 at 09:43 UTC

    use sprintf.

    my $result = sprintf "%03d", $number;

    Regards,
    Murugesan Kandasamy
    use perl for(;;);

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://541308]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2019-06-27 08:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Is there a future for codeless software?



    Results (111 votes). Check out past polls.

    Notices?