Use printf() or sprintf(). I wouldn't be able to explain the difference, maybe someone else will oblige. I'm always chuffed to learn the intracacies meself!
Code:
#!/usr/local/bin/perl
$test = 7 / 3;
$rounded = sprintf("%.0f\n", $test);
print "Content-type: text/html\n\n";
print "Test = $test<br>";
print "Rounded = $rounded";
exit;
The number of digits the integer is rounded to is determined by the first attribute in brackets:
No decimal point:
$rounded = sprintf("%.0f\n", $test);
Decimal point, rounded to two digits:
$rounded = sprintf("%.2f\n", $test);
Cheers,
adam
ps. Not too sure about that line break (\n) in the sprintf() function, I just pulled it from one of my scripts. Try it without...
[This message has been edited by dahamsta (edited May 27, 1999).]