Authored by 胡古飞

breakSizePercent保留两位小数

1 package com.yoho.search.consumer.service.logic.productIndex; 1 package com.yoho.search.consumer.service.logic.productIndex;
2 2
  3 +import java.math.BigDecimal;
3 import java.util.ArrayList; 4 import java.util.ArrayList;
4 import java.util.HashMap; 5 import java.util.HashMap;
5 import java.util.HashSet; 6 import java.util.HashSet;
@@ -148,13 +149,23 @@ public class ProductSizesLogicService { @@ -148,13 +149,23 @@ public class ProductSizesLogicService {
148 return results.toString().replaceFirst(",", ""); 149 return results.toString().replaceFirst(",", "");
149 } 150 }
150 151
  152 + /**
  153 + * 保留两位小数
  154 + *
  155 + * @param validStatusSizeCount
  156 + * @param hasStorageSizeCount
  157 + * @return
  158 + */
151 private double getBreakSizePercent(Integer validStatusSizeCount, Integer hasStorageSizeCount) { 159 private double getBreakSizePercent(Integer validStatusSizeCount, Integer hasStorageSizeCount) {
152 - if (validStatusSizeCount == null || validStatusSizeCount<=0) { 160 + if (validStatusSizeCount == null || validStatusSizeCount <= 0) {
153 return 100d; 161 return 100d;
154 } 162 }
155 - if (hasStorageSizeCount == null || hasStorageSizeCount<=0) { 163 + if (hasStorageSizeCount == null || hasStorageSizeCount <= 0) {
156 return 100d; 164 return 100d;
157 } 165 }
158 - return 100d * (validStatusSizeCount - hasStorageSizeCount) / validStatusSizeCount; 166 + double breakSizePercent = 100d * (validStatusSizeCount - hasStorageSizeCount) / validStatusSizeCount;
  167 + BigDecimal bg = new BigDecimal(breakSizePercent);
  168 + double result = bg.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
  169 + return result;
159 } 170 }
160 } 171 }