Role of parseFloat Method in JavaScript



Use the parseFloat() method in JavaScript to return a floating point number after parsing a string.

Example

You can try to run the following code to learn how to work with parseFloat() method in JavaScript.

<!DOCTYPE html>
<html>
   <body>
      <script>
         var val1 = parseFloat("2");
         var val2 = parseFloat("30 minutes");

         document.write(val1);
         document.write("<br>"+val2);
      </script>
   </body>
</html>
Updated on: 2020-05-23T11:04:59+05:30

163 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements