PHP common math built-in functions

Common math built-in functions in PHP:

 

1. Function: abs()

     Function: take the absolute value

     For example:

<?php

echo abs(-21.2);   // 当数字为  负数时

echo abs(21.2);    // 当数字为  正数时

<?

    result:

 

2. Function: max()

     Function: Get the largest number in a set of numbers

     For example:

<?php

echo max(2,4,5,-6,99);  // max() 函数的实例

?>

    result:

 

3. Function: min()

     Function: Take out the smallest number in a set of numbers

     For example:

<?php

echo min(2,4,5,-6,99);  // min() 函数的实例

?>

    result:

 

4. Function: ceil()

     Function: round up

     For example:

<?php

echo ceil(12.2)   // 当小数点后为  小于 5 时

echo ceil(0)      // 当为0 时

echo ceil(12.9)   // 当小数点后为  大于于 5 时

?>

    result:

5. Function: floor()

     Function: round down

     For example:

<?php

echo floor(12.2)   // 当小数点后为  小于 5 时

echo floor(0)      // 当为0 时

echo floor(12.9)   // 当小数点后为  大于于 5 时

?>

    result:

 

6. Function: round()

     Function: round floating point numbers

     For example:

<?php

echo round(12.2)   // 当小数点后为  小于 5 时

echo round(12)      // 当为整数 时

echo round(12.9)   // 当小数点后为  大于于 5 时

?>

    result:

 

7. Function: rand()

     Role: Generate random numbers

     For example:

<?php

echo rand(1,3)       // 范围是在 1 ~ 3

echo rand(-7,3)     // 范围是在 -7 ~ 3

echo rand(0.9999999999999999999)   // 范围是在 0 ~ 99999999999999999

echo rand()         // 随机产生数字

?>

    result:

Note:    The random number generation function rand(), the numbers generated are all integers (int), and the maximum number of positive integers it can generate is "9999999999999999999999" (that is, '20' '9').

Guess you like

Origin blog.csdn.net/qq_43269730/article/details/88591031