📋 Table Of Content
What is parseFloat()?
Example Convert String into Floating value
Here, we have some examples on how e can convert a string of numbers, strings or alphanumeric values into a floating point value.
parseFloat(" 20 ") parseFloat("12345abc") parseFloat("abc45678") parseFloat("3.1415") parseFloat("20 1 1999"
20 12345 NaN 3.1415 20
As you can see all the strings are parse as float value using parseFloat(). However to understand why some values are return as NaN (Not A Number ) and only the first digit, you have to see the description below.
parseFloat() arguments and return value descriptions
parseFloat()encounter a value other then + , - , 0-9, decimal point (.), exponent(e or E), it will ignore the invalid characters.
- Second decimal points are not parse by
parseFloat(). Any character up-to that is parse.
- Leading and trailing spaces are ignored.
- If the first character is not a number then it will return NaN (Not A Number)
- It can parse infinity.
BigIntvalues to Numbers .
- Check for prime number using for and while loop in Python
- Merge two dictionaries together using python (3 ways)
- Merge multiple JSON objects into one single object in Python
- Python - Check if list is empty or not
- Python - Insert an element at specific index in a list