Practical usage of MySQL mathematical functions

Source: Internet
Author: User
Tags decimal to binary mysql functions

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.

 
 
  1. mysql> select round(1.23);   
  2. +————-+   
  3. | round(1.23) |   
  4. +————-+   
  5. | 1 |   
  6. +————-+   
  7. 1 row in set (0.00 sec)   
  8. mysql> select round(1.56);   
  9. +————-+   
  10. | round(1.56) |   
  11. +————-+   
  12. | 2 |   
  13. +————-+   
  14. 1 row in set (0.00 sec) 

2) the number of decimal places can be set to return floating point data.

 
 
  1. mysql> select round(1.567,2);  
  2. +—————-+  
  3. | round(1.567,2) |  
  4. +—————-+  
  5. | 1.57 |  
  6. +—————-+  
  7. 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.

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.