sql语句中处理金额,把分换算成元
问题,sql语句中直接将金额/100返回的结果会有多个小数位。
select cate.cate_name as name,sum(acc.money)/100 as value from account as acc left join conCategory as cate on acc.cateCode=cate.cate_code group by cate_name
FORMAT(money/100,2)
select cate.cate_name as name,FORMAT(sum(acc.money)/100,2) as value from account as acc left join conCategory as cate on acc.cateCode=cate.cate_code group by cate_name
保留两位小数,但是千位会有逗号,有逗号的话echarts之类的会不识别这个数据
truncate(money,2)
直接截取小数点后两位,不进行四舍五入。
select cate.cate_name as name,truncate(sum(acc.money)/100,2) as value from account as acc left join conCategory as cate on acc.cateCode=cate.cate_code group by cate_name
OK
如果这篇文章对你有用,可以关注本人微信公众号获取更多ヽ(^ω^)ノ ~
![微信公众号二维码](https://images.cnblogs.com/cnblogs_com/aeolian/1679458/o_wechat_gzh_qrcode.jpg)