MySQL Numeric Functions
MySQL Numeric Functions
In this tutorial, we will learn about MySQL Numeric functions with examples. Numeric are mathematical functions that perform several types of operations such as rounding, truncation, generating random numbers, trigonometric calculations, etc.
MySQL Numeric Functions
Some functions are listed below:
Numeric Function |
Description |
ABS(<number>)
|
Returns the absolute value of number |
SIGN(<number>) | Returns-1,0 or depending on whether number is negative, zero or positive |
TRUNCATE(<number>, <decimals>) | Returns number truncated to decimals |
FLOOR(<number>) | Rounds number down to the closest lower integer |
CEILING (<number>) | Rounds number up to the closest higher integer |
ROUND(<number>) | Rounds number to the closest integer.Rounds up on DECIMAL data types It will round away from zero for >=0.5, to zero on < 0.5 |
Examples
mysql> SELECT ABS(-35), ABS(35) ;
+———-+———+
| ABS(-35) | ABS(35) |
+———-+———+
| 35 | 35 |
+———-+———+
1 row in set (0.00 sec)
mysql> SELECT SIGN(-1), SIGN(0), SIGN(1);
+———-+———+———+
| SIGN(-1) | SIGN(0) | SIGN(1) |
+———-+———+———+
| -1 | 0 | 1 |
+———-+———+———+
1 row in set (0.01 sec)
—
MySQL Tutorials
MySQL Tutorials on this website:
https://www.testingdocs.com/mysql-tutorials-for-beginners/