JavaScript toString () method
Examples
The number is converted to a string:
var num = 15;
var n = num.toString();
var n = num.toString();
n output:
15
try it"
Definition and Usage
A string representation. For example, when the radix is 2, NumberObject string will be represented as a binary value conversion.
Browser Support
All major browsers support toString () method
grammar
number.toString( radix )
Parameter Value
参数 | 描述 |
---|---|
radix | 可选。规定表示数字的基数,使 2 ~ 36 之间的整数。若省略该参数,则使用基数 10。但是要注意,如果该参数是 10 以外的其他值,则 ECMAScript 标准允许实现返回任意值。
|
return value
类型 | 描述 |
---|---|
String | 把数字转换为字符串 |
technical details
JavaScript version: | 1.1 |
---|
More examples
Examples
In this case, we used a different binary to convert a number to a string:
var num = 15;
var a = num.toString();
var b = num.toString(2);
var c = num.toString(8);
var d = num.toString(16);
var a = num.toString();
var b = num.toString(2);
var c = num.toString(8);
var d = num.toString(16);
a, b, c, and d output:
try it"