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; + } /* * 当前气象预警信息查询