parseFloat() function in JavaScript


The parseFloat() function accepts two parameters one is a string representing a number and another is a number representing the radix and returns an integer of the given radix.

Syntax

Its Syntax is as follows

num.parseFloat('4524', 8);

Example

 Live Demo

<html>
<head>
   <title>JavaScript Example</title>
</head>
<body>
   <script type="text/javascript">
      var result1 = parseFloat(Math.PI);
      document.write("Result: "+result1);
      document.write('<br>');
      var result2 = parseFloat("245.12@welcome");
      document.write("Result: "+result2);
      document.write('<br>');
      var result3 = parseFloat("11111100.010");
      document.write("Result: "+result3);
   </script>
</body>
</html>

Output

Result: 3.141592653589793
Result: 245.12
Result: 11111100.01

Updated on: 25-Jun-2020

84 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements