On Thu, 29 Jan 2004, Mallik wrote:

> How do I format the decimals, i.e, if there is no
> decimal part, then add .00, if there is one decimal,
> then add '0'.
> 
> For eg., how to convert 123 to 123.00
> and 123.5 to 123.50.



sprintf

Try this
-------------------------------------------------
#!/usr/bin/perl -w

while(<DATA>){
chomp;
$formatted = sprintf ("%0.2f",$_);
print "$formatted\n";
}

__DATA__
125
123.5
2
2.3456
34.6



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to