MySQL Query results after unit conversion number of decimal place retention method

Source: Internet
Author: User
Tags mysql query rounds

  1. 1. Call the MySQL formatted decimal function format (x,d)

    For example:

    [HTML]View PlainCopy
      1. Select Format (23456.789,2);
    [HTML]View PlainCopy
      1. Select Formate (salary,2);

    Output:

    [HTML]View PlainCopy
      1. 23,456.79

    , the format () function rounds the fractional part, and the integer part formats the output from right-to-left with a comma for every 3 bits, such as:

    2. Call MySQL's own function truncate (X,D)

    For example:

    [HTML]View PlainCopy
      1. Select truncate (23456.789,2);
    [HTML]View PlainCopy
      1. Select truncate (salary,2);

    Output:

    [HTML]View PlainCopy
      1. 23456.78

    The truncate () function will take the decimal portion of the 2-bit value directly out of the way, such as:

    3. Call MySQL's own function convert (expr,type);

    For example:

    [HTML]View PlainCopy
      1. Select CONVERT (23456.789,decimal (10,2));
    [HTML]View PlainCopy
      1. Select CONVERT (Salary,decimal (10,2));

    Output:

    [HTML]View PlainCopy
      1. 23456.79

    The CONVERT () function rounds the fractional part, explaining the decimal (10,2), which represents the resulting integer portion of the result, plus fractional bits of less than or equal to 10, and fractional bits of 2, such as:

    In general, we will choose the Third Way

MySQL Query results after unit conversion number of decimal place retention method

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.