价格问题处理

This commit is contained in:
gs
2024-06-25 18:00:21 +08:00
parent d491bef735
commit 2f86571578

View File

@@ -160,12 +160,14 @@ public class BTodayStockController {
String forObject = restTemplate.getForObject(apiUrl, String.class);
JSONObject jsonObject = JSON.parseObject(forObject);
String price = jsonObject.getString("price");
if (price != null) {
JSONArray arryData = jsonObject.getJSONArray("data");
if (arryData != null&&arryData.size()>0) {
try {
JSONObject jsonObject1 = arryData.getJSONObject(0);
String price = jsonObject1.getString("price");
double priceValue = Double.parseDouble(price);
DecimalFormat df = new DecimalFormat("0.00");
jsonObject.put("price", df.format(priceValue));
jsonObject1.put("price", df.format(priceValue));
} catch (NumberFormatException e) {
// Handle the case where price is not a valid double
e.printStackTrace();