Mysql format decimal point _ MySQL

Source: Internet
Author: User
Mysql format decimal point bitsCN.com

Today, I encountered a problem about formatting floating point numbers. I used format (col, 2) to keep two decimal places.

Select format (12562.6655, 2 );

Result: 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 is0, the result has no decimal point or fractional part. when the integer part exceeds three, it is separated by commas and the returned result is of the string type.

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'


If the expected results are not met, do not separate them with commas,

select truncate(4545.1366,2);

Result: there is still a problem when the screenshot is not rounded up.

select convert(4545.1366,decimal);

Result: 4545.14, as expected.BitsCN.com

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.