JavaScript parseFloat() function
- Previous Page
- Next Page
- Go Up One Level JavaScript Global Reference Manual
Definition and usage
parseFloat()
The function parses the string and returns a floating-point number.
This function determines whether the first character of the specified string is a digit. If it is, it parses the string until it reaches the end of the number, and returns the number as a number rather than a string.
Note:Only returns the first number in the string!
Note:Leading and trailing spaces are allowed.
Note:If the first character cannot be converted to a number,parseFloat()
Returns NaN.
Example
Parsing different strings:
var a = parseFloat("10") var b = parseFloat("10.00") var c = parseFloat("10.33") var d = parseFloat("34 45 66") var e = parseFloat(" 60 ") var f = parseFloat("40 years") var g = parseFloat("He was 40")
syntax
parseFloat(string)
Parameter Value
Parameter | Description |
---|---|
string | Required. The string to be parsed. |
Technical Details
Return Value: | Numbers. If the first character cannot be converted to a number, then returns NaN. |
---|---|
JavaScript Version: | ECMAScript 1 |
Browser Support
Function | Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|---|
parseFloat() | Support | Support | Support | Support | Support |
- Previous Page
- Next Page
- Go Up One Level JavaScript Global Reference Manual