From 416900240191fc08d5db74eb8f71ada56bfcaa37 Mon Sep 17 00:00:00 2001 From: zhaoxianglong Date: Fri, 31 May 2024 11:50:17 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=A4=A9=E6=B0=94=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=E8=A3=85=E5=A5=BD=E8=8C=83=E5=9B=B4=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/WeatherForecastController.java | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/zc-business/src/main/java/com/zc/business/controller/WeatherForecastController.java b/zc-business/src/main/java/com/zc/business/controller/WeatherForecastController.java index f15aaff6..516166b0 100644 --- a/zc-business/src/main/java/com/zc/business/controller/WeatherForecastController.java +++ b/zc-business/src/main/java/com/zc/business/controller/WeatherForecastController.java @@ -68,7 +68,7 @@ public class WeatherForecastController extends BaseController { String[] split1 = split[i].split("[+]"); String k = split1[0].replace("K", ""); int parseInt = Integer.parseInt(k); - numStake.append("K").append(parseInt).append("+000"); + numStake.append("K").append(findNearestMultipleOfFive(parseInt)).append("+000"); if (i != split.length - 1) { numStake.append("|"); } @@ -108,6 +108,24 @@ public class WeatherForecastController extends BaseController { return AjaxResult.error("请求失败"); } + public static int findNearestMultipleOfFive(int number) { + // 计算除以5的余数 + int remainder = number % 5; + + // 如果余数为0,则number已经是5的倍数 + if (remainder == 0) { + return number; + } + + // 如果余数不为0,则最近的5的倍数要么是number减去余数(如果余数小于3), + // 要么是number加上(5 - 余数)(如果余数大于或等于3) + // 这里选择的是较小的那个值(向上或向下取整) + int lowerMultiple = number - remainder; + int higherMultiple = number + (5 - remainder); + + // 返回两者中较小的那个 + return (lowerMultiple < higherMultiple) ? lowerMultiple : higherMultiple; + } /* * 当前气象预警信息查询