This article mainly describes the actual usage of MySQL mathematical functions and issues worth your attention in actual operations. MySQL mathematical functions are often used in MySQL functions, so it is helpful to have a certain understanding of it.
ABS (number2) // absolute value
BIN (decimal_number) // convert decimal to binary
CEILING (number2) // rounded up
CONV (number2, from_base, to_base) // hexadecimal conversion
FLOOR (number2) // round down
FORMAT (number, decimal_places) // number of reserved decimal places
HEX (DecimalNumber) // convert to hexadecimal
MySQL mathematical function Note: HEX () can input a string, returns its ASC-11 code, such as HEX ('def ') returns 4142143
You can also input a decimal integer to return its hexadecimal encoding. For example, HEX (25) returns 19.
LEAST (number, number2 [,...]) // calculates the minimum value.
MOD (numerator, denominator) // evaluate the remainder
POWER (number, power) // Exponent
RAND ([seed]) // Random Number
ROUND (number [, decimals]) // rounding, decimals is the number of decimal places]
Note: The return type is not an integer, for example:
(1) The default value is integer.
- mysql> select round(1.23);
- +————-+
- | round(1.23) |
- +————-+
- | 1 |
- +————-+
- 1 row in set (0.00 sec)
- mysql> select round(1.56);
- +————-+
- | round(1.56) |
- +————-+
- | 2 |
- +————-+
- 1 row in set (0.00 sec)
2) the number of decimal places can be set to return floating point data.
- mysql> select round(1.567,2);
- +—————-+
- | round(1.567,2) |
- +—————-+
- | 1.57 |
- +—————-+
- 1 row in set (0.00 sec)
SIGN (number2) // return SIGN, positive and negative or 0
SQRT (number2) // Square
The above content is an introduction to the MySQL mathematical functions. I hope you will get something better.