java 和sql 实现double小数位精确

round(AVG(a.amount), 3)  as "amount",
round(AVG(a.quality), 3)  as "quality",
round(AVG(a.quality_test), 3)  as "quality_test",
round(AVG(a.timely_delivery), 3)  as "timely_delivery",
round(AVG(a.pack), 3)  as "pack",
round(AVG(a.identify), 3)  as "identify",
round(AVG(a.coordination), 3)  as "coordination",

 

round(_data,x) X代表小数位位数

 

 

在java中

DecimalFormat df = new DecimalFormat("#.00");

attitude=0.300000030434;

attitude = df.format(attitude);

结果:attitude=0.30

#.00表示保留两个小数位

 

df.format(attitude);有个问题就是,转换后是字符串类型,而且如果最后的结果是0.XX的话,导出后显示的是 .xx,没有首位补充0,待解决;

你可能感兴趣的:(sql,数据库,java,sql)