OneBite.Dev - Coding blog in a bite size

convert variable from int to float in Javascript

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

  var numInt = 10;
  var numFloat = parseFloat(numInt);

In this code, we have a variable “numInt” that contains an integer value of 10. We then use the built-in Javascript function “parseFloat” to convert the integer value to a floating point value. The parseFloat function will read the string or number value passed to it and convert it to a floating point number. In this case, we are passing in our “numInt” variable, which will then be converted to a floating point number and stored in a new variable called “numFloat”.

javascript