当前位置: 移动技术网 > IT编程>数据库>Mysql > mysql格式化小数保留小数点后两位(小数点格式化)

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

2017年12月12日  | 移动技术网IT编程  | 我要评论
复制代码 代码如下:select format(12562.6655,2); 结果:12,562.67 查看文档:formats the number x to a f

复制代码 代码如下:

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,达到预期。

如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网