js中取模运算、求商及取整方法
2017-02-23 本文已影响0人
别别扭扭的王姑娘
在此整理一下js中的取模运算、求商及取整方法
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,user-scalable=no,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style></style>
<script>
//取模
document.write(1%2);
document.write(5%2);
//求商
console.log(1/2);
console.log(5/2);
//取整
console.log(parseInt(1/2));
console.log(parseInt(5/2));
//向上取整
console.log(Math.ceil(1/2));
//向下取整
console.log(Math.floor(5/2));
</script>
</head>
<body>
</body>
</html>
得到结果如下:
取模求商及取整.jpg