mysql> SELECT ceil (3.01); # in 1 rounding
+------------+
| Ceil (3.01) |
+------------+
| 4 |
+------------+
1 row in Set (0.00 sec)
mysql> SELECT Floor (3.99); # 1 rounding
+-------------+
| 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>
Mysql> SELECT 3 DIV 4; #整数除法
+---------+
| 3 DIV 4 |
+---------+
| 0 |
+---------+
1 row in Set (0.00 sec)
Mysql> SELECT 5% 3; #取余数
+-------+
| 5% 3 |
+-------+
| 2 |
+-------+
1 row in Set (0.00 sec)
Mysql> SELECT 5 MOD 3; #取余数
+---------+
| 5 MOD 3 |
+---------+
| 2 |
+---------+
1 row in Set (0.01 sec)
mysql> SELECT POWER (3,3); #幂运算
+------------+
| POWER (3,3) |
+------------+
| 27 |
+------------+
1 row in Set (0.05 sec)
mysql> SELECT ROUND (3.654, 2); #四舍五入
+-----------------+
| ROUND (3.654, 2) |
+-----------------+
| 3.65 |
+-----------------+
1 row in Set (0.00 sec)
Mysql> SELECT ROUND (3.654, 1);
+-----------------+
| ROUND (3.654, 1) |
+-----------------+
| 3.7 |
+-----------------+
1 row in Set (0.00 sec)
mysql> SELECT TRUNCATE (125.89, 2); # Digital Intercept
+---------------------+
| 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) |
+---------------------+
| |
+---------------------+
1 row in Set (0.00 sec)
Mysql> SELECT TRUNCATE (125.89, -1); #很少用到
+----------------------+
| TRUNCATE (125.89,-1) |
+----------------------+
| |
+----------------------+
MySQL numeric operators and functions