JavaScript floor()方法示例
<!DOCTYPE html>
<html>
<body>
<h3 style="color:Blue">JavaScript floor() Method Example</h3>
<p id="demo"></p>
<button onclick="myFunction()"点击</button>
<script type="text/javascript">
function myFunction() {
var a = Math.floor(0.70);
console.log("值1 : " + a);
var b = Math.floor(0.49);
console.log("<br />值2 : " + b);
var c = Math.floor(5);
console.log("<br />值3 : " + c);
var d = Math.floor(3.14);
console.log("<br />值4 : " + d);
var e = Math.floor(-5.1);
console.log("<br />值5 : " + e);
var f = Math.floor(-5.9);
console.log("<br />值6: " + f);
var x = document.getElementById("demo");
x.innerHTML = a + "<br>" + b + "<br>" + c + "<br>" + d + "<br>" + e + "<br>" + f;
}
</script>
</body>
</html>
JavaScript floor()方法
- Math对象的Floor()方法用于将数字向下舍入到最接近的整数。
- Floor()方法返回小于或者等于数字的最大整数。
- 在floor()方法中,如果参数值是一个整数,则该值将不会舍入。
语法
Math.floor(x)
日期:2020-04-18 01:09:22 来源:oir作者:oir
