MySQL numeric operators and functions

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.