- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
ParseFloat() can change a number string into a number whereas if any string other than a number is sent then it gives NaN as output.
It takes a number string as input and returns a floating point number as output.
In the following example, parseFloat() has given floating number as output, whereas parseInt() has given an integer as output.
<html> <body> <script> var a = parseFloat(" 100 "); document.write(a +"</br>"); var b = parseFloat("120.65") document.write(b +"</br>"); var c = parseInt("3.14"); document.write(c +"</br>"); </script> </body> </html>
100 120.65 3
In some cases there are both a number and also a string in a variable then, if the number is at first place then only the number will be returned as output, splicing out the string part, else NaN will be returned as output.
<html> <body> <script> var a = parseFloat(" hello ") document.write(a +"<br>"); var b = parseFloat("hello1234") document.write(b +"<br>"); var c = parseFloat("3.14hello"); document.write(c +"<br>"); </script> </body> </html>
NaN NaN 3.14
- Convert a floating point number to string in C
- How to count set bits in a floating point number in C?
- Fixed Point and Floating Point Number Representations
- Convert the specified double-precision floating point number to a 64-bit signed integer in C#
- Format floating point number in Java
- Reinterpret 64-bit signed integer to a double-precision floating point number in C#
- Convert string to a number in Java