此頁面由社群從英文翻譯而來。了解更多並加入 MDN Web Docs 社群。
Math.ceil()
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2015年7月.
Math.ceil() 靜態方法總是無條件進位,並回傳大於或等於給定數字的最小整數。
In this article
嘗試一下
console.log(Math.ceil(0.95));// 預期輸出:1console.log(Math.ceil(4));// 預期輸出:4console.log(Math.ceil(7.004));// 預期輸出:8console.log(Math.ceil(-7.004));// 預期輸出:-7語法
js
Math.ceil(x)參數
x一個數字。
回傳值
大於或等於x 的最小整數。其值與-Math.floor(-x) 相同。
描述
因為ceil() 是Math 的靜態方法,你應該總是使用Math.ceil(),而不是作為你建立的Math 物件的方法(Math 不是一個建構子)。
範例
>使用 Math.ceil()
js
Math.ceil(-Infinity); // -InfinityMath.ceil(-7.004); // -7Math.ceil(-4); // -4Math.ceil(-0.95); // -0Math.ceil(-0); // -0Math.ceil(0); // 0Math.ceil(0.95); // 1Math.ceil(4); // 4Math.ceil(7.004); // 8Math.ceil(Infinity); // Infinity規範
| Specification |
|---|
| ECMAScript® 2026 Language Specification> # sec-math.ceil> |