On Wednesday, April 17, 2002, at 10:12 , bob ackerman wrote:
> for integers:
> (add one) divide by 2.
> $rndup = ($var+1)/2;
that would give you a float....
print "half of $_ rounded up is " . ( ($_ + 1) / 2) . "\n"
foreach (@ARGV) ;
perl /tmp/drieux/roundup.pl 1 2 3 4 5 6
half of 1 rounded up is 1
half of 2 rounded up is 1.5
half of 3 rounded up is 2
half of 4 rounded up is 2.5
half of 5 rounded up is 3
half of 6 rounded up is 3.5
but:
print "half of $_ rounded up is " . int(( $_ / 2) + 0.5 ) . "\n"
foreach (@ARGV) ;
will give you:
perl /tmp/drieux/roundup.pl 1 2 3 4 5 6
half of 1 rounded up is 1
half of 2 rounded up is 1
half of 3 rounded up is 2
half of 4 rounded up is 2
half of 5 rounded up is 3
half of 6 rounded up is 3
ciao
drieux
---
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]