mysql格式化小数保留小数点后两位(小数点格式化)


代码如下:

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);
 
mysql保留字段小数点后两位小数
用函数:truncate(s.price,2)即可。
如果想用四舍五入的话用round(s.price,2)。
 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM