Double 四舍五入

@Override
	public String execute() throws Exception {
		if (update != null && update.trim().length() != 0) {
			return INPUT;
		}
		Map<String, Object> map = subjectService.getResult(id);

		list = (List<Option>) map.get("list");
		Map<String, Object> map1 = (Map<String, Object>) map.get("rows");
		id = Integer.parseInt(map1.get("id").toString());
		title = map1.get("title").toString();
		options = Integer.parseInt(map1.get("options").toString());
		peoples = Integer.parseInt(map1.get("peoples").toString());
		
		System.out.println("result========"+result);
		
		if (result != null && result.trim().length() != 0) {
			Double temp = null;
			BigDecimal round = null;
			List list2 = (List) map1.get("progress");
			for (int i = 0; i < list2.size(); i++) {
				Map<String, Object> map2 = (Map<String, Object>) list2.get(i);
				allCount += Integer.parseInt(map2.get("count").toString());
			}

			for (int i = 0; i < list2.size(); i++) {
				Map<String, String> resultMap = new HashMap<>();
				Map<String, Object> map2 = (Map<String, Object>) list2.get(i);
				resultMap.put("orderId", map2.get("orderId").toString());
				resultMap.put("optionName", map2.get("optionName").toString());
				resultMap.put("count", map2.get("count").toString());
				if (allCount == 0) {
					resultMap.put("percent", 0 + "");
				} else {
					temp = (double) Integer.parseInt(map2.get("count").toString());
					temp = (double) temp / allCount * 100;
					round = new BigDecimal(temp);
					temp = round.setScale(2, RoundingMode.HALF_UP).doubleValue();
					resultMap.put("percent", temp.toString());
				}
				resultList.add(resultMap);
			}
			return NONE;
		}
		return SUCCESS;
	}
	```
上一篇:219. 存在重复元素 II


下一篇:[LeetCode] #219 存在重复元素 II