Php – Math functions. FunctionDescription abs()Returns the absolute value of a number...

5
php – Math functions

Transcript of Php – Math functions. FunctionDescription abs()Returns the absolute value of a number...

Page 1: Php – Math functions. FunctionDescription abs()Returns the absolute value of a number ceil()Returns the value of a number rounded upwards to the nearest.

php – Math functions

Page 2: Php – Math functions. FunctionDescription abs()Returns the absolute value of a number ceil()Returns the value of a number rounded upwards to the nearest.

Function Descriptionabs() Returns the absolute value of a numberceil() Returns the value of a number rounded upwards to the nearest integerfloor() Returns the value of a number rounded downwards to the nearest integeris_nan() Returns true if a value is not a numberlcg_value() Returns a pseudo random number in the range of (0,1)max() Returns the number with the highest value of two specified numbersmin() Returns the number with the lowest value of two specified numberspow() Returns the value of x to the power of ymt_rand() Returns a random integer using Mersenne Twister algorithmrand() Returns a random integerround() Rounds a number to the nearest integersqrt() Returns the square root of a number

常用數學函數

Page 3: Php – Math functions. FunctionDescription abs()Returns the absolute value of a number ceil()Returns the value of a number rounded upwards to the nearest.

亂數float lcg_value ()產生介於 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/>"; ?>

Page 4: Php – Math functions. FunctionDescription abs()Returns the absolute value of a number ceil()Returns the value of a number rounded upwards to the nearest.

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

Page 5: Php – Math functions. FunctionDescription abs()Returns the absolute value of a number ceil()Returns the value of a number rounded upwards to the nearest.

二 , 八 , 十 , 十六進位轉換

base_convert() Converts a number from one base to anotherbindec() Converts a binary number to a decimal numberdecbin() Converts a decimal number to a binary numberdechex() Converts a decimal number to a hexadecimal numberdecoct() Converts a decimal number to an octal numberhexdec() Converts a hexadecimal number to a decimal numberoctdec() Converts an octal number to a decimal number