Ask a Question related to PERL Beginners, Design and Development.
-
Mallik #1
Formatting the decimals
Dear Friends,
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.
Thanks in advance,
Mallik.
Mallik Guest
-
Formatting decimals with 2 digits - 3.70 vs 3.7000 ???
I am formatting decimals on several columns within my DataGrid. For the most part it is working correctly. However, 2 of the columns will not... -
CFINPUT and decimals
Hi.. I am encountering an odd problem... I have a series of CFINPUT statements in a form...The table that the data for the form comes from... -
Decimals not Getting into ASP
We have an ASP page that grabs data from an Oracle 9i table and then dumps it into another. It had been working great until we swapped out servers.... -
how to keep decimals from rounding
Is there a way to surpress round() or number_format() from rounding decimal places? I have a value of ".253338" being returned via a calc... -
Formatting Decimals in a Combo Box or List Box
I am having trouble with a couple of things. On separate forms, even different databases I have either a control that is a combo box or a field in... -
Owen Cook #2
Re: Formatting the decimals
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
Owen Cook Guest
-
John W. Krahn #3
Re: Formatting the decimals
Mallik wrote:
Hello,>
> Dear Friends,
printf "%.2f\n", $_ for 123, 123.5;> 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.
John
--
use Perl;
program
fulfillment
John W. Krahn Guest
-
Adam #4
Re: Formatting the decimals
Owen is dead on, but I think we can do that with less code. Try
something like:
printf ("%0.2f\n", $_) while (<>);
Regards,
Adam
On Jan 29, 2004, at 5:25 AM, Owen Cook wrote:>
> 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.6Adam Guest



Reply With Quote

