Description
The toString() method is used to convert a Number object to a string, and return the result.
This method has the form:
number.toString(radix)
Parameter | Description |
---|---|
radix | (optional) Which base to use for representing a numeric value. Must be an integer between 2 and 36.
|
Note: This method is called by JavaScript automatically whenever a Number object needs to be displayed as a string.
Examples
The following example shows the basic use of this method.
<script>
var num = new Number(15);
document.write(num.toString());
document.write("<br />");
document.write(num.toString(2));
document.write("<br />");
document.write(num.toString(8));
document.write("<br />");
document.write(num.toString(16));
document.write("<br />");
</script>
This produces the following result:
Browser Support
Firefox | IE | Chrome | Opera | Safari |
---|---|---|---|---|