[aclug-L] Re: Formatting numbers in Perl!
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
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
- [aclug-L] Formatting numbers in Perl!, Mohammad Islam, 2000/10/20
- [aclug-L] Re: Formatting numbers in Perl!,
Steven Saner <=
- [aclug-L] Re: Formatting numbers in Perl!, Mohammad Islam, 2000/10/20
- [aclug-L] Re: Formatting numbers in Perl!, Jesse Kaufman, 2000/10/20
- [aclug-L] Re: Formatting numbers in Perl!, Jeremy King, 2000/10/20
- [aclug-L] Re: Formatting numbers in Perl!, Jeff Schaller, 2000/10/20
- [aclug-L] Re: Formatting numbers in Perl!, Steven Saner, 2000/10/20
- [aclug-L] Re: Formatting numbers in Perl!, Jeff Schaller, 2000/10/20
|
|