Mega Code Archive

 
Categories / JavaScript Tutorial / Number Data Type
 

ParseFloat() method

The parseFloat() method starts in position 0. It continues until the first invalid character and then converts the string it has seen up to that point. The decimal point is a valid character the first time it appears. The string "22.34.5" will be parsed into 22.34. The string must represent a floating-point number in decimal form, not octal or hexadecimal. This method ignores leading zeros. The hexadecimal number 0xA will return NaN because x isn't a valid character for a floating-point number. There is also no radix mode for parseFloat(). var fNum1 = parseFloat("1234AAA"); var fNum2 = parseFloat("0xA"); var fNum3 = parseFloat("2.5"); var fNum4 = parseFloat("2.34.5"); var fNum5 = parseFloat("0908"); var fNum6 = parseFloat("blue");