To convert a float to a string in JavaScript, you can use the toString()
method of the Number object.
In this example,
float1
with a value of 3.14
.toString()
method to convert the float to a string and store the result in a variable str1
.str1
to the console.// Convert Float 3.14 to String
let float1 = 3.14;
let str1 = float1.toString();
console.log('String value is:', str1);
String value is: 3.14
In this example,
float2
with a value of 10.5
.toString()
method to convert the float to a string and store the result in a variable str2
.str2
to the console.// Convert Float 10.5 to String
let float2 = 10.5;
let str2 = float2.toString();
console.log('String value is:', str2);
String value is: 10.5
In this tutorial, we learned How to convert Float to String in JavaScript language with well detailed examples.