Browse Source

Merge pull request #858 from dahuoyzs/v5-dev

补充Math.ceilDiv()除法运算向上取整
Golden Looly 5 years ago
parent
commit
ec4b1cdd5f
1 changed files with 12 additions and 0 deletions
  1. 12 0
      hutool-core/src/main/java/cn/hutool/core/util/NumberUtil.java

+ 12 - 0
hutool-core/src/main/java/cn/hutool/core/util/NumberUtil.java

@@ -752,6 +752,18 @@ public class NumberUtil {
 		return v1.divide(v2, scale, roundingMode);
 	}
 
+	/**
+	 * 补充Math.ceilDiv() JDK8中添加了和Math.floorDiv()但却没有ceilDiv()
+	 *
+	 * @param v1           被除数
+	 * @param v2           除数
+	 * @return 两个参数的商
+	 * @since 5.3.3
+	 */
+	public static int ceilDiv(int v1, int v2) {
+		return (int)Math.ceil((double)v1 / v2);
+	}
+
 	// ------------------------------------------------------------------------------------------- round
 
 	/**