Open In App

JavaScript Program for Double to String Conversion

Last Updated : 23 Feb, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

Converting a double (floating-point) number to a string in JavaScript involves transforming the numeric value into its corresponding string representation. This process is essential when dealing with numeric data that needs to be displayed or manipulated as strings, such as in user interfaces or data formatting tasks.

Using the toString() method

Utilize the toString() method available for JavaScript number objects to convert the double to a string. This method converts the number to its string representation.

Example: The below example implements the toString() method for Double to String Conversion in JavaScript.

Javascript




const num = 3.14159;
const str = num.toString();
console.log(typeof num, typeof str);


Output

number string

Using the String() Constructor

Use the String() constructor function to convert the double to a string. This approach explicitly converts the number to a string.

Example: The below example implements the String() Constructor for Double to String Conversion in JavaScript.

Javascript




const num = 3.14159;
const str = String(num);
console.log(typeof num, typeof str);


Output

number string

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads