PHP中常用的数学函数

PHP中常用的数学函数如下:

/**
 * 数学函数
 */
$abs =  abs(-3.3);  // return float|int The absolute value of number
$ceil = ceil(2.0001); // return float value rounded up to the next highest
$floor = floor(3.9);  // return float value rounded to the next lowest integer.
$fmod = fmod(3,2);    // return float The floating point remainder of
$pow = pow(2,3);  // return int|float base raised to the power of exp.
$round = round(4.5);    // return float The rounded value
$sqrt = sqrt(9);        // return float The square root of arg
$max = max(1,2,3,4,5,6,7);  // return mixed max returns the numerically highest of the parameter values, either within a arg array or two arguments.
$min = min(0.9,1,2,3,4,5,6,7); // return mixed min returns the numerically lowest of the parameter values.
$mt_rand = mt_rand(1000,9999);  // return int A random integer value between min (or 0)
$rand = rand(1000,9999);  // return int A pseudo random value between min (or 0) and max (or getrandmax, inclusive)
$pi = pi();  // return float The value of pi as float

echo 'abs:'.$abs,"\n",'ceil:'.$ceil,"\n".'floor:'.$floor,"\n".'fmod:'.$fmod,
    "\n".'pow:'.$pow,"\n".'round:'.$round,"\n".'sqrt:'.$sqrt,"\n".'max:'.$max,
    "\n".'min:'.$min, "\n".'mt_rand:'.$mt_rand."\n",'rand:'.$rand."\n".'pi:'.$pi;
// output
abs:3.3 ceil:3 floor:3 fmod:1 pow:8 round:5 sqrt:3 max:7 min:0.9 mt_rand:9186 rand:2872 pi:3.1415926535898

你可能感兴趣的:(PHP中常用的数学函数)