Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

print 001 instead of 1
Hello all,
I have a variable named n. n is a number from 0 to 999. I want to print
it with always 3 digits (like 002 instead 2). How do I do it? If I use
printf ("%3d",$n), it uses spaces...

Best regards,
-vcf

Report this thread to moderator Post Follow-up to this message
Old Post
Vitor Flausino
03-30-05 08:56 PM


Re: print 001 instead of 1
In article <424aab9f$0$6570$4d4efb8e@read.news.pt.uu.net>, Vitor
Flausino <vflausino@dti.pga.aero> wrote:

> Hello all,
> I have a variable named n. n is a number from 0 to 999. I want to print
> it with always 3 digits (like 002 instead 2). How do I do it? If I use
> printf ("%3d",$n), it uses spaces...

Try printf("%3.3d,$n);


----== Posted via mcse.ms - Unlimited-Uncensored-Secure Usenet News==-
---
http://www.mcse.ms The #1 Newsgroup Service in the World! >100,000 New
sgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---

Report this thread to moderator Post Follow-up to this message
Old Post
Jim Gibson
03-30-05 08:56 PM


Re: print 001 instead of 1
Vitor Flausino wrote:

> printf ("%3d",$n), it uses spaces...

Sounds like you haven't looked at the first example shown by
perldoc -f sprintf

-Joe

Report this thread to moderator Post Follow-up to this message
Old Post
Joe Smith
03-31-05 01:56 AM


Re: print 001 instead of 1
On Wed, 30 Mar 2005 11:07:27 -0800, Jim Gibson
<jgibson@mail.arc.nasa.gov> wrote:

>In article <424aab9f$0$6570$4d4efb8e@read.news.pt.uu.net>, Vitor
>Flausino <vflausino@dti.pga.aero> wrote:
> 
>
>Try printf("%3.3d,$n);

or rather
printf("%03d",$n);

--
mvh/Regards Kåre Olai Lindbach
(News: Remove '_delete_' and '.invalid')
(HTML-written email from unknown will be discarded)

Report this thread to moderator Post Follow-up to this message
Old Post
Kåre Olai Lindbach
03-31-05 01:56 AM


Re: print 001 instead of 1
"Vitor Flausino" <vflausino@dti.pga.aero> wrote in message
news:424aab9f$0$6570$4d4efb8e@read.news.pt.uu.net...
> Hello all,
> I have a variable named n. n is a number from 0 to 999. I want to print it
> with always 3 digits (like 002 instead 2). How do I do it? If I use printf
> ("%3d",$n), it uses spaces...


printf "%03d",$n;



Report this thread to moderator Post Follow-up to this message
Old Post
Tintin
03-31-05 08:57 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PERL Programming archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 07:05 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.