service_fee 字段定义:`service_fee` decimal(14,4) NULL DEFAULT NULL COMMENT '手续费金额,含税' ,
需求:service_fee 求和,并保留两位小数。若整数5,即结果应为:5.00
1)round(sum(service_fee),2)
数据库可视化工具 Navicat 上执行:一切正常……
mysql> select round(sum(service_fee),2) as serviceFree from tableName; +-------------+ | serviceFree | +-------------+ | 85850.10 | +-------------+ 1 row in set mysql>
此字段进行了求和,四舍五入,保留两位小数,然而页面没有显示需要的格式
2)cast(round(sum(service_fee),2) as char)
数据库可视化工具 Navicat 上执行:一切正常……
mysql> select cast(round(sum(service_fee),2) as char) serviceFree from tableName; +-------------+ | serviceFree | +-------------+ | 85850.10 | +-------------+ 1 row in set mysql>
呈现到页面,满足需求……