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