A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Math/ceil below:

Math.ceil() - JavaScript | MDN

Math.ceil()

Baseline Widely available

Math.ceil() 静态方法总是向上舍入,并返回大于等于给定数字的最小整数。

尝试一下
console.log(Math.ceil(0.95));
// Expected output: 1

console.log(Math.ceil(4));
// Expected output: 4

console.log(Math.ceil(7.004));
// Expected output: 8

console.log(Math.ceil(-7.004));
// Expected output: -7
语法 参数 返回值

大于等于 x 的最小整数。它的值与 -Math.floor(-x) 相同。

描述

因为 ceil() 是 Math 的静态方法,所以你应始终使用 Math.ceil(),而不是作为你创建的 Math 对象的方法(Math 不是构造函数)。

示例 使用 Math.ceil()
Math.ceil(-Infinity); // -Infinity
Math.ceil(-7.004); // -7
Math.ceil(-4); // -4
Math.ceil(-0.95); // -0
Math.ceil(-0); // -0
Math.ceil(0); // 0
Math.ceil(0.95); // 1
Math.ceil(4); // 4
Math.ceil(7.004); // 8
Math.ceil(Infinity); // Infinity
规范 浏览器兼容性 参见

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4