[VPM] always floating point?

Carl B. Constantine cconstan at csc.UVic.CA
Mon Mar 31 16:06:53 CST 2003


I know that I can format a number into a floating point using standard
printf statements like this: printf "\$%6.2f\n",$studTotal;

However, what if I always want a number to be a floating point value
regardless of the printf? For example, consider the following:

my $rate = 7;  # 7 cents per page printing

print $rate/100;

will print 0.07. But if I have:

my $rate = 50; # 50 cents per page colour printer

print $rate/100;

will print: .5 unless I use printf's and format it: 0.50.

How can I have it always to be 0.50 without using printf statements? so
I want to do this:

my $cents = $rate/100;

my $string = "$cents per page";

print $string;

would yield: 0.50 per page

This is for use in the Text::Table module, so I kind of need it like
this or it prints .5 instead of 0.50, 0 instead of 0.00, and 0.07 as it
should. There is a reason for it which goes into more detail and I can
explain it better later, I'm just curious if I can do this or not.

Thanks.


-- 
Carl B. Constantine         University of Victoria
Programmer Analyst          http://www.csc.uvic.ca
UNIX System Administrator   Victoria, BC, Canada
cconstan at csc.uvic.ca        ELW A220, 721-8753



More information about the Victoria-pm mailing list