JavaScript Math.floor方法(对数值向下取整)
JavaScriptMath.floor方法
Math.floor方法用于对数值向下取整,即得到小于或等于该数值的最大整数。语法如下:
Math.floor(x)
参数说明:
说明
x
必需。必须是一个数值。
提示:该方法与Math.ceil方法正好相反。
Math.floor方法实例
<scriptlanguage="JavaScript"> document.write(Math.floor(0.35)+"<br/>"); document.write(Math.floor(10)+"<br/>"); document.write(Math.floor(-10)+"<br/>"); document.write(Math.floor(-10.1)); </script>
运行该例子,输出:
0
10
-10
-11
Math.floor可能不准的问题
如果参数x是一个涉及浮点数的表达式,那么由于计算机的固有原理,可能导致表达式应用Math.floor方法后结果不准确(不符合常理),具体参考《Math.ceil方法》一文中的相关描述。
热门推荐
1 狗狗下楼训练
3 狗狗训练头盔
6 狗狗训练机构
7 训练狗狗步骤
9 狗狗能训练
10 狗狗基本动作训练方法
11 怎么训练狗狗叼饭盆
12 狗狗一岁了还能训练吗
13 训练狗狗的
14 宁波狗狗训练
15 训练狗狗拉屎
16 教狗狗训练
17 狗狗要怎么训练上厕所
18 狗狗靠的训练