新闻时间处理

This commit is contained in:
gs
2024-06-25 17:45:15 +08:00
parent 74c64eb7d4
commit d491bef735

View File

@@ -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;
}