OneBite.Dev - Coding blog in a bite size

convert variable from float to string in Javascript

Code snippet on how to convert variable from float to string in Javascript

  let floatVal = 3.14; 
  let stringVal = floatVal.toString(); 

This code creates two variables. The first is called ‘floatVal’ and is set to the float 3.14. The second is called ‘stringVal’ and is set to the value of ‘floatVal’ converted to a string. The built-in Javascript method ‘.toString()’ is used to convert the variable value from a float to a string. As a result, the variable ‘stringVal’ will have the value of ‘3.14’ in string form, instead of float form.

javascript