mysql格式化小數

今天遇到一個問題,格式化浮點數的問題,用format(col,2)保留兩位小數點,出現一個問題,例如

 SELECT FORMAT(12562.6655,2);

結果:12,562.67

 查看文檔: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.整數部分超過三位的時候以逗號分割,並且返回的結果是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'


沒有達到預期結果,想要的結果不要以逗號分隔,

 select truncate(4545.1366,2);

 結果:4545.13,直接截取不四捨五入,還是有問題。

 select convert(4545.1366,decimal);

結果:4545.14,達到預期。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章