Home > Database > Mysql Tutorial > body text

mysql 数值处理函数floor与round

WBOY
Release: 2016-06-07 15:07:13
Original
1459 people have browsed it

在mysql中,当处理数时,会用到数处理函数,如有一个float型数2.13,你想只要整数2,那就需要下面的函数floor与round。 floor:函数只返回整数部分,小数部分舍弃。 round:函数四舍五入,大于0.5的部分进位,不到则舍弃。与floor不同。如下测试 mysql selec

  在mysql中,当处理数值时,会用到数值处理函数,如有一个float型数值2.13,你想只要整数2,那就需要下面的函数floor与round。

floor:函数只返回整数部分,小数部分舍弃。

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)

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)





source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!