Complete.Org: Mailing Lists: Archives: discussion: October 2000:
[aclug-L] Re: Formatting numbers in Perl!
Home

[aclug-L] Re: Formatting numbers in Perl!

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: discussion@xxxxxxxxx
Subject: [aclug-L] Re: Formatting numbers in Perl!
From: Steven Saner <ssaner@xxxxxxxxxxxxxxx>
Date: Fri, 20 Oct 2000 01:13:18 -0500
Reply-to: discussion@xxxxxxxxx

You can use the sprintf, which is the same as printf except that it
will print to a string. So something like:

$sub_total = sprintf "%.2d", $price * $quantity;


On Fri, Oct 20, 2000 at 12:14:21AM -0500, Mohammad Islam wrote:
> Hi,
> 
> I was wondering someone can provide  some pointers regarding formatting
> numbers in perl.
> 
> Lets say I have the following variables:
> 
> $price = $49.50;
> $quantity = 2;
> 
> $sub_total = $price * $quantity 
> 
> print $subtotal show 99.
> 
> Now I want $sub_total to be $99.00 [up to two decimal places].
> 
> How can go about accomplishing it? I have looked into printf from the
> "Learning Perl" book, but i do not intend to print to the screen. I want
> to store the formatted value to another variable for later use.
> 
> Any help would be gratly appreciated.
> 
> Thanks.
> 
> Moe
> 
> -- This is the discussion@xxxxxxxxx list.  To unsubscribe,
> visit http://tmp2.complete.org/cgi-bin/listargate-aclug.cgi

-- This is the discussion@xxxxxxxxx list.  To unsubscribe,
visit http://tmp2.complete.org/cgi-bin/listargate-aclug.cgi


[Prev in Thread] Current Thread [Next in Thread]