zoukankan      html  css  js  c++  java
  • 类型转换

     
        <script language="javascript" type="text/javascript">
            //boolean()强制转换,当参数为空字符串和null时,得到false
            document.write("强制转换<br />");
            document.write(Boolean('')+"<br />");
            document.write(Boolean(100)+"<br />");
            document.write(Boolean(null)+"<br />");
            document.write(Boolean(new Object())+"<br />");
            //转换
            var sColor="violet";
            document.write(sColor.length,"<br />");
            var bFound=false;
            document.write(bFound.toString(),"<br />");
            var iNum=10;
            document.write("10的二进制数为",iNum.toString(2),"<br />");
            document.write("10的八进制数为",iNum.toString(8),"<br />");
            document.write("10的十进制数为",iNum.toString(10),"<br />");
            //转换成数字
            function testFunction(){}
            document.write(Number(testFunction()),"<br />");
            document.write(Number("123.23"),"<br />");
            document.write(Number(false),"<br />");
            document.write(Number(true),"<br />");
            document.write(parseInt("58"), "<br />");
            document.write(parseFloat("56.6"), "<br />");
          //-------------------------输出结果---------------------------------
          //强制转换
          //false
          //true
          //false
          //true
          //6
          //false
          //10的二进制数为1010
          //10的八进制数为12
          //10的十进制数为10
          //NaN
          //123.23
          //0
          //1
          //58
          //56.6

        </script>
  • 相关阅读:
    JavaUtil_04_验证码生成器
    Java微信公众平台开发_02_启用服务器配置
    Log4j2_学习_01_Log4j 2使用教程
    Java_Time_01_获取当前时间
    Eclipse_配置_00_资源帖
    Eclipse_插件_02_jd-eclipse插件的安装
    noip模拟题题解集
    小结:高斯消元
    10月刷题总结
    【vijos】1892 树上的最大匹配(树形dp+计数)
  • 原文地址:https://www.cnblogs.com/chengpeng/p/2104271.html
Copyright © 2011-2022 走看看