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方法》一文中的相关描述。
热门推荐
10 感谢韩语老师祝福语简短
11 升职文案高级祝福语简短
12 花童结婚祝福语大全简短
13 向国庆送祝福语简短
14 什么寄语简短祝福语女生
15 客户回礼祝福语大全简短
16 女孩生日祝福语简短创意
17 家长回复节日祝福语简短
18 给外婆敬酒祝福语简短