可以为toString()方法传递一个表示基数的参数

2017-06-16 14:05:00
admin
原创
313
<!DOCTYPE html>
<html>
<head>
    <title>Number Type Example</title>
    <script type="text/javascript">
        var numberObject = new Number(10);
        var numberValue = 99;
        
        //toString() using a radix
        alert(numberObject.toString());       //"10"
        alert(numberObject.toString(2));      //"1010"
        alert(numberObject.toString(8));      //"12"
        alert(numberObject.toString(10));     //"10"
        alert(numberObject.toString(16));     //"a"
        
        //toFixed()
        alert(numberObject.toFixed(2));    //outputs "10.00"

        numberObject = new Number(99);
        alert(numberObject.toPrecision(1));    //"1e+2"
        alert(numberObject.toPrecision(2));    //"99"
        alert(numberObject.toPrecision(3));    //"99.0"
           
        alert(typeof numberObject);   //object
        alert(typeof numberValue);    //number
        alert(numberObject instanceof Number);  //true
        alert(numberValue instanceof Number);   //false
        
    </script>
</head>
<body>

</body>
</html>
文章分类
联系我们
电话: 18902328227
Email: 2689701946@qq.com
QQ: 2689701946
微信: 18902328227
地址: 广州番禺区繁华路
  • 在线客服
  • 关注微信
  • 联系电话
    • 欢迎咨询
    • 欢迎加入QQ群 303257430
  • 公众号:源宝网络
    • 联系电话及微信号 18902328227