...

View Full Version : Making All calulations = integers



srule_
01-05-2008, 02:36 AM
Hello, Is there a way to tell PHP That I only want Round numbers (No floating point numbers) in a certain calculation.

bcarl314
01-05-2008, 05:29 AM
This may help:
http://us2.php.net/manual/en/function.intval.php



$output = intval($must_be_int) * 3;
print $output;

dumpfi
01-05-2008, 12:27 PM
Other options are:
$myInt = (int) (5 / 3); // cast to int -> will truncate the fraction part
$myInt = floor(5 / 3); // rounds down to the next lower integer -> same as a cast
$myInt = round(5 / 3); // rounds to the nearest integer
$myInt = ceil(5 / 3); // rounds up to the next higher integer
dumpfi



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum