From d491bef7359858b9056ae8679b9eab2699b8aa1e Mon Sep 17 00:00:00 2001 From: gs Date: Tue, 25 Jun 2024 17:45:15 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E9=97=BB=E6=97=B6=E9=97=B4=E5=A4=84?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cn/stock/market/web/BTodayStockController.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/main/java/cn/stock/market/web/BTodayStockController.java b/src/main/java/cn/stock/market/web/BTodayStockController.java index 1692773..34066cb 100644 --- a/src/main/java/cn/stock/market/web/BTodayStockController.java +++ b/src/main/java/cn/stock/market/web/BTodayStockController.java @@ -22,6 +22,7 @@ import org.springframework.web.bind.annotation.RestController; import org.springframework.web.client.RestTemplate; import java.math.BigDecimal; +import java.text.DecimalFormat; import java.util.List; import java.util.Map; @@ -159,6 +160,17 @@ public class BTodayStockController { String forObject = restTemplate.getForObject(apiUrl, String.class); JSONObject jsonObject = JSON.parseObject(forObject); + String price = jsonObject.getString("price"); + if (price != null) { + try { + double priceValue = Double.parseDouble(price); + DecimalFormat df = new DecimalFormat("0.00"); + jsonObject.put("price", df.format(priceValue)); + } catch (NumberFormatException e) { + // Handle the case where price is not a valid double + e.printStackTrace(); + } + } jsonObject.put("id",btodayStock.getId()); return jsonObject; }