對於普通加減法運算,此處不予詳細講解,如下例:
mysql> SELECT 3+4; +-----+ | 3+4 | +-----+ | 7 | +-----+ 1 row in set (0.03 sec)
CEIL和FLOOR
#CEIL為向上取整,只要有小數位,不管是幾,直接入一位。例如:
mysql> SELECT CEIL(3.01); +------------+ | CEIL(3.01) | +------------+ | 4 | +------------+ 1 row in set (0.02 sec)
FLOOR與此
相反
mysql> SELECT FLOOR(3.99); +-------------+ | FLOOR(3.99) | +-------------+ | 3 | +-------------+ 1 row in set (0.00 sec)
mysql> SELECT 3/4; +--------+ | 3/4 | +--------+ | 0.7500 | +--------+ 1 row in set (0.00 sec) mysql> SELECT 3 p 4; +---------+ | 3 p 4 | +---------+ | 0 | +---------+ 1 row in set (0.00 sec) mysql> SELECT 3 MOD 4; +---------+ | 3 MOD 4 | +---------+ | 3 | +---------+ 1 row in set (0.00 sec)# ##註:MOD可以換成%############POWER冪運算#############例如3的2次方###
mysql> SELECT POWER(3,2); +------------+ | POWER(3,2) | +------------+ | 9 | +------------+ 1 row in set (0.14 sec)#### #####ROUND四捨五入############例如3.652保留小數點後兩位。 ###
mysql> SELECT ROUND(3.652,2); +----------------+ | ROUND(3.652,2) | +----------------+ | 3.65 | +----------------+ 1 row in set (0.00 sec)###保留小數點後面一位:###
mysql> SELECT ROUND(3.652,1); +----------------+ | ROUND(3.652,1) | +----------------+ | 3.7 | +----------------+ 1 row in set (0.00 sec)##################TRUNCATE############################################################ #直接去掉某幾位######
mysql> SELECT TRUNCATE(125.89,2); +--------------------+ | TRUNCATE(125.89,2) | +--------------------+ | 125.89 | +--------------------+ 1 row in set (0.00 sec) mysql> SELECT TRUNCATE(125.89,1); +--------------------+ | TRUNCATE(125.89,1) | +--------------------+ | 125.8 | +--------------------+ 1 row in set (0.00 sec) mysql> SELECT TRUNCATE(125.89,0); +--------------------+ | TRUNCATE(125.89,0) | +--------------------+ | 125 | +--------------------+ 1 row in set (0.00 sec) mysql> SELECT TRUNCATE(125.89,-1); +---------------------+ | TRUNCATE(125.89,-1) | +---------------------+ | 120 | +---------------------+ 1 row in set (0.00 sec)### 以上就是MySQL數值運算子和函數的內容,更多相關內容請關注PHP中文網(www.php.cn)! #########################