Welcome to the Linux community forum and interact with 2 million technical staff. Today, we have encountered a problem: format (col, 2) is used to keep two decimal points, for example, SELECTFORMAT (12562.6655, 2); Result: 12,562.67 view document: FormatsthenumberXtoaformatlike
Welcome to the Linux community forum, and interact with 2 million technical staff> today, we have encountered a problem, the problem of formatting floating point numbers, using format (col, 2) to retain two decimal points, a problem occurs, for example, select format (12562.6655, 2); Result: 12,562.67 view document: Formats the number X to a format like
Welcome to the Linux community forum and interact with 2 million technicians>
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
See the 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, the result has no decimal point or fractional part. when the integer part exceeds three digits, it is separated by commas and the returned result is of the string type.
Mysql> select format (12332.123456, 4 );
-> '123'
Mysql> select format (12332.1, 4 );
-> '123'
Mysql> select format (12332.2, 0 );
-> '123'
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.