JavaScript

Convert int to string in Javascript

In this tutorial, we are going to see how to convert a number to a string using the toString(base) function which allows converting a given number into a string. The base parameter is optional, which can be used to specify the base in which the number will be represented.
 

Convert int to string in Javascript
var nbr = 15;
nbr.toString(); //"15"
nbr.toString(2); //"1111"(binary)
nbr.toString(8); //"17"(octa)
nbr.toString(16); //"f"(hexa)

This also works for floating point and exponential numbers.

var nbr = 20.4;
nbr.toString(); //"20.4"
mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

Your email address will not be published. Required fields are marked *