From c84096324e7562f49ffe48b3a4b149f29b2b3d52 Mon Sep 17 00:00:00 2001 From: wjc <1243177876@qq.com> Date: 星期二, 24 十二月 2024 16:05:50 +0800 Subject: [PATCH] 2024年12月24日16:05:48 --- app/src/main/java/com/hdl/photovoltaic/other/HdlCommonLogic.java | 39 +++++++++++++++++++++++++++++++++++---- 1 files changed, 35 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/hdl/photovoltaic/other/HdlCommonLogic.java b/app/src/main/java/com/hdl/photovoltaic/other/HdlCommonLogic.java index 4124f7a..1edf0e8 100644 --- a/app/src/main/java/com/hdl/photovoltaic/other/HdlCommonLogic.java +++ b/app/src/main/java/com/hdl/photovoltaic/other/HdlCommonLogic.java @@ -101,12 +101,13 @@ if (TextUtils.isEmpty(value)) { return UnitType.noValue + unit; } - if (unit.equals(UnitType.kW)) { + if (unit.equals(UnitType.kW) || unit.equals(UnitType.kWh)) { return divideByOneThousandAndFormat(value).toString() + unit; } return getBigDecimal(value).toString() + unit; } + /** * @param value 鍊� @@ -160,11 +161,41 @@ * @return BigDecimal */ public static BigDecimal divideByOneThousandAndFormat(String value) { - double doubleValue = Double.parseDouble(value); - BigDecimal bigDecimal = new BigDecimal(doubleValue); - return bigDecimal.divide(new BigDecimal(1000), 2, RoundingMode.HALF_EVEN); + try { + double doubleValue = Double.parseDouble(value); + int val = 1000; + if (doubleValue > 1000 && doubleValue < 1000 * 1000) { + val = 1000; + } else if (doubleValue > 1000 * 1000 && doubleValue < 1000 * 1000 * 1000) { + val = 1000 * 1000; + } else if (doubleValue > 1000 * 1000 * 1000) { + val = 1000 * 1000 * 1000; + } + BigDecimal bigDecimal = new BigDecimal(doubleValue); + return bigDecimal.divide(new BigDecimal(val), 2, RoundingMode.HALF_EVEN); + } catch (Exception e) { + BigDecimal bigDecimal = new BigDecimal(0); + return bigDecimal.divide(new BigDecimal(1000), 2, RoundingMode.HALF_EVEN); + } } + /** + * 鑾峰彇鍊嶆暟 + * + * @param value 鍊� + */ + public static int val(String value) { + double doubleValue = Double.parseDouble(value); + int val = 1000; + if (doubleValue > 1000 && doubleValue < 1000 * 1000) { + val = 1000; + } else if (doubleValue > 1000 * 1000 && doubleValue < 1000 * 1000 * 1000) { + val = 1000 * 1000; + } else if (doubleValue > 1000 * 1000 * 1000) { + val = 1000 * 1000 * 1000; + } + return val; + } /** * 鐢熸垚浜岀淮鐮� -- Gitblit v1.8.0