> whenever you need to do any special formatting like this, 
> especially numbers, use the "sprintf()" in  perlfunc - Perl 
> builtin functions for your case, try this:
> 
> print sprintf("%05.02f\n", 4.5 );
> 04.50

Why not just use 'printf()' for this? Makes it somewhat less confusing
while doing essentially the same thing in the background:

printf "%05.02f\n", 4.5;

The difference lies in if the '$\' ($OUTPUT_RECORD_SEPERATOR) is set
when you use the first example it will add an extra newline that you
probably would not intend (given the \n in the format). printf() will
ignore the value of $\ and format only according to your format
argument.

Just a suggestion.

Matt



> 
> -----Original Message-----
> From: Sara [mailto:[EMAIL PROTECTED] 
> Sent: Wednesday, August 20, 2003 1:21 PM
> To: beginperl
> Subject: Formatting integer input
> 
> 
> $one = 2.5;
> $two = 2;
> $three = $one + $two;
> 
> print "$three"; # prints     4.5
> 
> I want 4.5 in proper format as 04.05
> 
> Any ideas?
> 
> Thanks,
> Sara.
> 
> 
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to