A few ways depending on your exact need...

(See: perldoc -f int)
my $x = int(10/3); # $x = 3

(See: perldoc integer)
use integer;
my $x = 10 / 3; # $x = 3

(See: perldoc -f sprintf)
my $x = sprintf("%d", 10/3); # $x = 3 (rounded down)

Rob


-----Original Message-----
From: Ling F. Zhang [mailto:[EMAIL PROTECTED]
Sent: Tuesday, July 01, 2003 7:04 AM
To: [EMAIL PROTECTED]
Subject: math stuff...


okay...I am glad @ how easy it is to use perl scalar
both as numerical value and string...but sometimes I
just need to do integer division the C way:

when 10/3, I want it to equal to 3, not 3.33333....
is there an operator for such operation? or do I have
to do like:
$a=10
$b=3
$c=$a/$b; # c=3.33333....
$d=$c-$a%$b/$b; # d =3

or a one-liner:
$d = ($a - $a % $b)/%b;

__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com

-- 
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]

Reply via email to