int will go towards zero...
#!/usr/bin/perl -w
my ($p, $q, $r, $s, $t);
use POSIX;
use strict;
$p = rand( 100 ); # random number between 0 and 100
$q = int( $p ); # goes towards zero
$r = ceil( $p ); # goes to next highest integer
$s = floor( $p ); # goes to next lowest integer
print " rand: $p \n";
print " int: $q \n";
print " ceil: $r \n";
print " floor: $s \n";
if ( $p - $s >= .5 ){
$t = $r
} else {
$t = $s
}
print "rounded: $t\n";
-----Original Message-----
From: _brian_d_foy [mailto:[EMAIL PROTECTED]]
Sent: Thursday, October 18, 2001 2:31 PM
To: [EMAIL PROTECTED]
Subject: Re: Fraction to integer.
In article <[EMAIL PROTECTED]>,
[EMAIL PROTECTED] (Amit Joshi) wrote:
> Is there a way in perl to directly convert a fractional number to
> its nearest integer value ??
use the int() function.
http://www.perldoc.com/perl5.6.1/pod/func/int.html
--
brian d foy <[EMAIL PROTECTED]> - Perl services for hire
CGI Meta FAQ - http://www.perl.org/CGI_MetaFAQ.html
Troubleshooting CGI scripts - http://www.perl.org/troubleshooting_CGI.html
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]