MySQL formatted decimal two digits after decimal (decimal point formatting)

Source: Internet
Author: User

The problem of formatting the floating-point number, using Format (col,2) to retain the two-bit decimal point, there is a problem, such as the following statement, after we give a workaround

SELECT FORMAT (12562.6655,2);

Results: 12,562.67

View Document: Formats The number X to a format like ' #,###,###.## ', rounded to D decimal places, and returns the result as a string . If D is 0 and the result has a no decimal point or a fractional part that is more than three bits long with a comma, and the result returned is of type string.

Mysql> Select Format (12332.123456, 4);-> ' 12,332.1235 ' mysql> Select Format (12332.1,4);-> ' 12,332.1000 ' Mysql> SELECT FORMAT (12332.2,0);-> ' 12,332 '
Do not achieve the expected results, do not want the results separated by commas,
Select truncate (4545.1366,2);

Results: 4545.13, direct interception does not round, or there is a problem.

Select CONVERT (4545.1366,decimal);

Results: 4545.14, reached the expected.

Add: Convert cannot be rounded to reach the message, and convert has the same effect as truncate, intercepting two digits after the decimal point.

Rounding retains two digits after decimal point: ROUND (x,d)

Select ROUND (4545.1366,2);

Results: 4545.15, reached the expected.

MySQL formatted decimal two digits after decimal (decimal point formatting)

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.