Use the toString() function to convert numbers to strings in JavaScript. This method is a built-in method of the JavaScript Number object that allows you to convert any number type value into its string type representation.
Ways to Convert a number to a string:-
String(n)
n.toString()
""+n
n+""
Example convert number to string in JavaScript
Simple example code use toString(). Use it when needs to be displayed as text.
<!DOCTYPE html>
<html>
<body>
<script>
var num = 24;
var str = num.toString();
console.log(num);
console.log(typeof(str))
</script>
</body>
</html>
Output:
Another example
This method also converts floating and negative numbers.
20.toString(); // Error: Invalid or unexpected token
(20).toString(); // "20"
(10.7).toString(); // "10.7"
(-20).toString(); // "-20"
Do comment if you have any doubts or suggestions on this JS conversion of number topic.
Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.
OS: Windows 10
Code: HTML 5 Version