CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
%'s and decimal points

 



nook6
newbie

Jul 3, 2001, 1:52 PM

Post #1 of 2 (631 views)
%'s and decimal points Can't Post

HI
I'm new here and i have a problem??

I'm trying to add a percentage into a script I'm writing i have it added in but it is putting a decimal point in with numbers after it is there anyway i can stop that so it only used whole numbers ???

At the moment I'm using percentages like this

my $number = 11;
my $total = ($number * 0.25);
print "$total";

This is just an example but thats the sort of thing I'm using i want it only to count whole numbers though i don't want it decimalized.
i thank you all in advance for your help



mhx
Enthusiast / Moderator

Jul 3, 2001, 2:21 PM

Post #2 of 2 (630 views)
Re: %'s and decimal points [In reply to] Can't Post

Hi,

you can use the printf function, for example:

Code
my $number = 11; 
my $total = ($number * 0.25);
printf "%.0f", $total;

This will actually round $total. If you rather want to truncate $total, you can use either

Code
my $number = 11; 
my $total = ($number * 0.25);
printf "%d", $total;

or

Code
my $number = 11; 
my $total = int($number * 0.25);
print $total;

Hope this helps.

-- Marcus


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives