Function: Obtain the entire functions round and floor in MySQL.

Source: Internet
Author: User

Function: Example of taking the entire function round and floor in MySQL:

 round(123.456,2)      ------------   123.47ROUND   (   numeric_expression   ,   length   [   ,   function   ]   )   

 

The numeric_expression parameter is an expression of exact or approximate numeric data type (except for bit data type ). Length is the precision of numeric_expression to be rounded. The length must be tinyint, smallint, or int. When length is a positive number, numeric_expression is rounded to the specified decimal place. When length is a negative number, numeric_expression is rounded to the left of the decimal point specified by length. Function is the operation type to be executed. The function must be tinyint, smallint, or int. If the value of function or function is omitted is 0 (default), numeric_expression is rounded. When a value other than 0 is specified, numeric_expression is truncated.
round(123.456,   0)     -------         123.000     SELECT   FLOOR(123.45),   FLOOR(-123.45),   FLOOR($123.45)   ---------             ---------           -----------   123                         -124                     123.0000           SELECT   CEILING(123.45),   CEILING(-123.45),   CEILING(0.0) 

 

The result set is as follows: --------- ----------------------- 124-123 0 ///////////////////////////////// /////////////////// // The TRUNC of ORACLE is all-encompassing, the TRUNC of DB2 is only used for numbers. But can be implemented like DATE. For example, DATE (a timestamp field) removes all the values after TIMESTAMP into a pure date, just as ORACLE's TRUNC (SYSDATE) removes the subsequent time.
SQL> select trunc(2345.6789,2) from dual;TRUNC(2345.6789,2)------------------           2345.67/home/db2inst > db2 -v "select decimal(2345.6789,10,2) from sysibm.sysdummy1"select decimal(2345.6789,10,2) from sysibm.sysdummy11------------     2345.67  1 record(s) selected.

 


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.