English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
JavaScript Global Properties/Function
parseFloat()Function parses parameters and returns a floating-point number.
If encountered with symbol(+or-、number(0-9Characters other than parentheses, decimal points, or exponents, returns the value before the character and ignores the character and all subsequent characters. Allows leading and trailing spaces.
If the value is a string and the first character cannot be converted to a number, parseFloat() returns NaN.
parseFloat(value)
parseFloat("12"); // 12 parseFloat("12.25"); // 12.25 parseFloat("34 45 66");// 34 parseFloat(" 20 ");// 20 parseFloat('314e-2'); // 3.14 parseFloat('0.0314E+2'); // 3.14 parseFloat('3.14 more non-digit characters');// 3.14Test See‹/›
All browsers fully support the parseFloat() function:
Function | |||||
parseFloat() | Yes | Yes | Yes | Yes | Yes |
Parameter | Description |
---|---|
value | The value you want to parse |
Return Value: | Returns a floating-point number parsed from the given value. If the value cannot be converted to a number, returns NaN. |
---|---|
JavaScript Version: | ECMAScript 1 |