RainBows
2015-08-08 00:13
parseInt转化不好 吗
额、、、骚等,两个是不一样的!遇到正数转换结果相同,但是负数就完全不同了,Math.floor(-1.8)=-2 parseInt(-1.8)=-1 所以两者还是不同的!!!parseInt()只不过是去掉小数点强制化整!
我觉得一样吧因为我用下面这个程序测试了一下
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Math </title>
<script type="text/javascript">
if(Math.ceil(Math.random()) == parseInt(Math.random())){
document.write("True");
}
else{
document.write("False");
}
</script>
</head>
<body>
</body>
</html>返回结果一直是true,换做其他数字也是true
如有不对,欢迎拍砖!
JavaScript进阶篇
469382 学习 · 22585 问题
相似问题