mysql數值處理函數floor與round
在mysql中,當處理數值時,會用到數值處理函數,如有一個float型數值2.13,你想只要整數2,那就需要下面的函數floor與round。
floor:函數只返回整數部分,小數部分捨棄。
www.2cto.com
round:函數四捨五入,大於0.5的部分進位,不到則捨棄。與floor不同。如下測試
mysql> select floor(5.1);
+------------+
| floor(5.1) |
+------------+
| 5 |
+------------+
1 row in set (0.00 sec)
mysql> select floor(5.5);
+------------+
| floor(5.5) |
+------------+
| 5 |
+------------+
1 row in set (0.00 sec)
www.2cto.com
mysql> select round(5.2);
+------------+
| round(5.2) |
+------------+
| 5 |
+------------+
1 row in set (0.00 sec)
mysql> select round(5.5);
+------------+
| round(5.5) |
+------------+
| 6 |
+------------+
1 row in set (0.00 sec)