Commit 8c7f659b by 高晓磊

设置为2位小数(四舍五入)

parent a716a1ce
...@@ -15,6 +15,8 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -15,6 +15,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.*; import java.util.*;
...@@ -89,7 +91,7 @@ public class PriceAdjustmentServiceImpl implements PriceAdjustmentService { ...@@ -89,7 +91,7 @@ public class PriceAdjustmentServiceImpl implements PriceAdjustmentService {
Map<String, List<TimeValue>> collect = timeValues.stream().collect(Collectors.groupingBy(timeValue -> finalDateFormat.format(timeValue.getTime()))); Map<String, List<TimeValue>> collect = timeValues.stream().collect(Collectors.groupingBy(timeValue -> finalDateFormat.format(timeValue.getTime())));
collect.forEach((s, timeValues1) -> { collect.forEach((s, timeValues1) -> {
try { try {
timeValues2.add(new TimeValue(UUID.randomUUID(),finalDateFormat.parse(s),timeValues1.stream().mapToDouble(TimeValue::getValue).summaryStatistics().getAverage())); timeValues2.add(new TimeValue(UUID.randomUUID(),finalDateFormat.parse(s), BigDecimal.valueOf(timeValues1.stream().mapToDouble(TimeValue::getValue).summaryStatistics().getAverage()).setScale(2, RoundingMode.HALF_UP).doubleValue()));
} catch (ParseException e) { } catch (ParseException e) {
e.printStackTrace(); e.printStackTrace();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment