MySQL retains two decimal places

Source: Internet
Author: User

1, round (X,D): For data rounding, round (x), in fact, is round (x,0), also is the default d is 0;

One of the notable points here is that D can be a negative number, when the D-bit integer bit to the left of the specified decimal point is 0, and the decimal places are 0;

SELECT ROUND (100.3465,2), ROUND (100,2), ROUND (0.6,2), ROUND (114.6,-1);

Results were: 100.35,100,0.6,110

2. TRUNCATE (x,d): The function returns the number x that is removed to the D-digit after the decimal point. If the value of D is 0, the result does not have a decimal point or a fractional part. If D is set to a negative number, then the value of all lows after the beginning of the first digit of the decimal point (zero) x is truncated.

SELECT TRUNCATE (100.3465,2), TRUNCATE (100,2), TRUNCATE (0.6,2), TRUNCATE (114.6,-1);

Results were: 100.34,100,0.6,110

3. FORMAT (x,d): Force the D Decimal, the integer part exceeds three bits, and the returned result is a string type

SELECT format (100.3465,2), Format (100,2), format (, 100.6,2);

Results were: 100.35,100.00,100.60

4. CONVERT (value,type); type conversion, equivalent to interception

Type

    • Binary, with binary prefix effect: binary
    • Character type, with parameters: CHAR ()
    • Date: Date
    • Time:
    • DateTime Date/Time type
    • Floating point number: DECIMAL
    • Integer: Signed
    • unsigned integer: UNSIGNED

SELECT Convert (100.3465,decimal (10,2)), CONVERT (100,decimal (10,2)), CONVERT (100.4,decimal (10,2));

Results were: 100.35,100,100.4

MySQL retains two decimal places

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.