zoukankan      html  css  js  c++  java
  • javascript 中parseInt 的用法

    <!DOCTYPE html>
    <html>
    <head lang="en">
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
    <script>
        console.log(parseInt(19.11));        //19
        console.log(parseInt(-19.11));        //-19
        console.log(parseInt(19.99));        //19
        console.log(parseInt(-19.99));        //-19
        console.log(parseInt("25.93px"));        //25
        console.log(parseInt("px25px"));        //NaN
        console.log(parseInt(110,2));            //6
    </script>
    </body>
    </html>
     
    由以上例子可以看出parseInt作用
    1.函数可解析一个字符串,并返回一个整数。
    2.舍去小数点后的数字不进行四舍五入。
    3.可以转换进制。
    4.当以不是表达进制开头的字母(如0x)时,就无法识别返回NaN
  • 相关阅读:
    ERROR: epmd error for host "yourhostname": timeout
    leetcode485
    leetcode463
    leetcode496
    leetcode344
    leetcode412
    leetcode500
    leetcode476
    leetcode557
    leetcode461
  • 原文地址:https://www.cnblogs.com/xiao-song/p/5812689.html
Copyright © 2011-2022 走看看