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 小托班祝福语简短
10 简短的几句新年祝福语
11 长辈生日欢快祝福语简短
12 员工喜事祝福语简短精辟
13 公司年会祝福语简短最好
14 男生的生日祝福语简短
15 简短宝贝祝福语大全集
16 女儿成年祝福语简短霸气
17 祝福语简短独特教官
18 送大三祝福语简短