问答详情
源自:7-16 随机数 random()

parseInt转化不好 吗

parseInt转化不好 吗

提问者:RainBows 2015-08-08 00:13

个回答

  • Annguowenhua
    2015-08-12 16:51:20

    额、、、骚等,两个是不一样的!遇到正数转换结果相同,但是负数就完全不同了,Math.floor(-1.8)=-2 parseInt(-1.8)=-1  所以两者还是不同的!!!parseInt()只不过是去掉小数点强制化整!

  • Annguowenhua
    2015-08-12 16:46:19

    我觉得一样吧因为我用下面这个程序测试了一下

    <!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

    如有不对,欢迎拍砖!