JavaScript Number.toString() Method

You are Here:

JavaScript Number.toString() Method

The Number.toString() method returns a string representing the specified Number object.

Example

HTML Online Editor
<!DOCTYPE html> <html> <body> <script> var numObj = 12; var result = numObj.toString(2); document.write(result); </script> </body> </html>

Syntax

Number.toString(radix)

Parameter Values

ValueTypeExplanation
radixOptionalAn integer in the range 2 through 36 specifying the base to use for representing numeric values.
  • 2 - The number will show as a binary value
  • 8 - The number will show as an octal value
  • 16 - The number will show as an hexadecimal value

Return Value

ValueExplanation
stringReturns a string representing the specified Number object.

More Examples

Example

HTML Online Editor
<!DOCTYPE html> <html> <body> <script> var numObj = 12; var bin = numObj.toString(2); var oct = numObj.toString(8); var hexa = numObj.toString(16); document.write("binary 12 ="+ bin); document.write("<br>octal 12 = "+ oct); document.write("<br>hexa 12 = "+ hexa); </script> </body> </html>

Reminder

Hi Developers, we almost covered 97% of JavaScript Tutorials with examples for quick and easy learning.

We are working to cover every Single Concept in JavaScript.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author