parseInt转化不好 吗

来源:7-16 随机数 random()

RainBows

2015-08-08 00:13

parseInt转化不好 吗

写回答 关注

2回答

  • 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

    如有不对,欢迎拍砖!

JavaScript进阶篇

本课程从如何插入JS代码开始,带您进入网页动态交互世界

468980 学习 · 22582 问题

查看课程

相似问题