Skip to content

JavaScript int to float | Conversion example code

  • by

Use parseFloat() with to toFixed() method to convert int to float in JavaScript. Where toFixed() method formats a number using fixed-point notation. Read MDN Web Docs for full reference.

Example int to float in JavaScript

Simple example code parseFloat takes in a string value and converts it to float.

<!DOCTYPE html>
<html>
<head>

  <script>
    var n = 10;
    var res = parseFloat(n).toFixed(2);
    console.log(res); 

    var x = 8;
    var out = parseFloat(x).toFixed(3);
    console.log(out); 
  </script>
</head>
<body>

</body>
</html>

Output:

JavaScript int to float

Do comment if you have any doubts or suggestions on this JS int to float topic.

Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.

OS: Windows 10

Code: HTML 5 Version

Leave a Reply

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