
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
How to get a string representation of a number in JavaScript?
Use the toString() method to get the string representation of a number. You can try to run the following code to print a string representation of numbers like 20, -40, 15.5 −
Example
<!DOCTYPE html> <html> <body> <script> var num1 = 25; document.write(num1.toString()+"<br>"); document.write((30.2).toString()+"<br>"); var num2 = 3; document.write(num2.toString(2)+"<br>"); document.write((-0xff).toString(2)); </script> </body> </html>
Output
25 30.2 11 -11111111
Above, you can see we added a parameter to the toString() method. This is an optional parameter, which allows you to add an integer between 2 and 36, which is the base for representing numeric values.
- Related Articles
- How to get a number value of a string in Javascript?
- How to get a number of vowels in a string in JavaScript?
- In MySQL, how we can get the corresponding string representation of the binary value of a number?
- How to get the length of a string in JavaScript?
- How to get the string representation of numbers using toString() in Java?
- How to get the cosine of a number in JavaScript?
- How to get the sine of a number in JavaScript?
- How to get the tangent of a number in JavaScript?
- How to get the length of a Number in JavaScript?
- How to convert a String representation of a Dictionary to a dictionary in Python?
- How to get a part of string after a specified character in JavaScript?
- How to get the length of a string in bytes in JavaScript?
- How to add a number and a string in JavaScript?
- How to get the square root of a number in JavaScript?
- How to get the exponent power of a number in JavaScript?

Advertisements