Gossamer Forum
Home : General : Perl Programming :

rounding decimal places

Quote Reply
rounding decimal places
I know that this is a simple question, but I am relatively new to perl.

Here is the scalar that I have:
Code:
# Calculate the average rating

$average = $sum/$numhits; # this the average rating

Sometimes the decimals go on forever, like 7.66666666667. How would I go about rounding the $average scalar to only the first to decimal places, like this 7.67?


Quote Reply
Re: rounding decimal places In reply to
You're welcome



------------------
Regards,
hooter

Quote Reply
Re: rounding decimal places In reply to
Code:
# Calculate the average rating
$average = $sum/$numhits; # this the average rating

Code:
$average = $sum/$numhits;
$format_average = sprintf("%.2f",$average);



------------------
Regards,
hooter

Quote Reply
Re: rounding decimal places In reply to
It works perfectly, thanks!

------------------
Robert Blackstone
Webmaster of Scato Search
www.scato.com