Reserve two decimal places for mysql decimal formatting

  • 2020-06-07 05:24:11
  • OfStack


SELECT FORMAT(12562.6655,2);

Results: 12562.67

View documentation: Formats the to a like '#,###,###.##', rounded to decimal places, and returns the as a is 0, the result has no point or fractional part. Integer parts larger than 3 digits are separated by commas and return a result 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 separate desired results by commas,


select truncate(4545.1366,2);

Results: 4545.13, direct interception is not rounded into 5, there is still a problem.


select convert(4545.1366,decimal);

Results: 4545.14, reaching the expected.


Related articles: