Presentation is loading. Please wait.

Presentation is loading. Please wait.

Php – Math functions.

Similar presentations


Presentation on theme: "Php – Math functions."— Presentation transcript:

1 php – Math functions

2 常用數學函數 Function Description abs()
Returns the absolute value of a number ceil() Returns the value of a number rounded upwards to the nearest integer floor() Returns the value of a number rounded downwards to the nearest integer is_nan() Returns true if a value is not a number lcg_value() Returns a pseudo random number in the range of (0,1) max() Returns the number with the highest value of two specified numbers min() Returns the number with the lowest value of two specified numbers pow() Returns the value of x to the power of y mt_rand() Returns a random integer using Mersenne Twister algorithm rand() Returns a random integer round() Rounds a number to the nearest integer sqrt() Returns the square root of a number

3 亂數 float lcg_value () int mt_rand(min, max) int rand(min, max)
產生介於0與1之浮點亂數 int mt_rand(min, max) int rand(min, max) 產生介於min與max之整數亂數 <?php echo lcg_value()."<br/>"; echo rand(1,49)."<br/>"; echo mt_rand(1,49)."<br/>"; ?>

4 四捨五入 <?php echo round(3.4); // 3 echo round(3.5); // 4 echo round(3.6); // 4 echo round(3.6, 0); // 4 echo round(3.6); // 4 echo round( , 2); // 1.96 echo round( , -3); // echo round(5.045, 2); // 5.05 echo round(5.055, 2); // 5.06 ?>

5 二, 八, 十, 十六進位轉換 base_convert()
Converts a number from one base to another bindec() Converts a binary number to a decimal number decbin() Converts a decimal number to a binary number dechex() Converts a decimal number to a hexadecimal number decoct() Converts a decimal number to an octal number hexdec() Converts a hexadecimal number to a decimal number octdec() Converts an octal number to a decimal number


Download ppt "Php – Math functions."

Similar presentations


Ads by Google