MySQL-精度-sum(double类型)有精度问题,产生很多的小数,直接ROUND保留两位
可能适合对结果要求不高的
String sql =
"select sum(if(`a50anquanjixiaojine` = '',0,`a50anquanjixiaojine`)) as 原始结果," +
"ROUND(sum(if(`a50anquanjixiaojine` = '',0,`a50anquanjixiaojine`)),2) as ROUND2位小数结果," +
"sum(CAST(if(`a50anquanjixiaojine` = '',0,`a50anquanjixiaojine`) AS decimal(65,2))) as 转成decimal结果 " + //这个位数最长测试达到65
"from ent_tebiandiangonghse_datapool_a50anquanjixiao where `disable` <> 1 and `danweimingchengerji` in ('新疆天池能源有限责任公司')and `danweimingchengerji` is not null and `danweimingchengerji` <> '' group by `danweimingchengerji`";
List<Map<String, Object>> maps = baseMapper.executeSql4Select(sql);
String result = JSON.toJSONString(maps);
System.out.println(result);
result:
[{"原始结果":-1042425.2999999999,"ROUND2位小数结果":-1042425.3,"转成decimal结果":-1042425.30}]
正文到此结束