What does it mean when there is a number parameter passed to toString?

后端 未结 3 1691
耶瑟儿~
耶瑟儿~ 2020-12-25 12:10

I\'m just wondering what it means to attach a number as a parameter to the toString() method

E.g. obj.toString(10);

I googled a

3条回答
  •  余生分开走
    2020-12-25 12:41

    This only works on Number objects and is intended to give you a way of displaying a number with a certain radix:

    var n = 256;
    var d = n.toString(10); // decimal: "256"
    var o = n.toString(8);  // octal:   "400"
    var h = n.toString(16); // hex:     "100"
    var b = n.toString(2);  // binary:  "100000000"
    var w = n.toString(20); // base 20: "cg"
    

    Note that the radix must be an integer between 2 and 36 or toString() will raise an error.

提交回复
热议问题