Home > Web Front-end > JS Tutorial > JavaScript ParseFloat() method_javascript skills

JavaScript ParseFloat() method_javascript skills

WBOY
Release: 2016-05-16 15:24:45
Original
2178 people have browsed it

Definition and usage of parseFloat() method:

The parseFloat() method can parse a string and return a floating point number.

Note: If the first character in the string cannot be converted into a number, this method returns NaN. If the string contains multiple numbers, only the first number will be returned.

Click to view more global methods and properties of ECMAScript.

Grammar structure:

Copy code The code is as follows:

parseFloat(string)

Parameter list:

参数 描述
string 必需。要被解析的字符串。

Example code:

Copy code The code is as follows:

console.log(parseFloat("123"));

Output result: 123.

Copy code The code is as follows:

console.log(parseFloat("123,321"));

Only the first number can be returned. Output result: 123.

Copy code The code is as follows:

console.log(parseFloat("N321"));

The first character cannot be converted to a number. Output result: NaN.

Copy code The code is as follows:

console.log(parseFloat("12 years old"));

Output result: 12.

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template