double sellPrice = 8.1;//或者8效果明显不同
double costPrice = sellPrice * 0.3;//当为0.5一般就都是两位小数,就不要后面处理,但是为0.3double就会在后面生成很多小数
double marketPrice = sellPrice * 0.29;if ((marketPrice*1000)%10>0) {
DecimalFormat df=new DecimalFormat("#.00");//这个格式化有个问题,就是当为5的时候就不能四舍五入,而是把5舍掉不要了
if((marketPrice*1000)%10==5.0){
marketPrice=Double.valueOf(df.format(marketPrice))+0.01;
}else {
marketPrice=Double.valueOf(df.format(marketPrice));
}
}
if ((costPrice*1000)%10>0) {
DecimalFormat df=new DecimalFormat("#.00");
if((costPrice*1000)%10==5.0){
costPrice=Double.valueOf(df.format(costPrice))+0.01;
}else {
costPrice=Double.valueOf(df.format(costPrice));
}
}