JavaScript Number.parseFloat()

Examples

Number.parseFloat(10);
Number.parseFloat("10");
Number.parseFloat("10.33");
Number.parseFloat("34 45 66");
Number.parseFloat("He was 40");
Try it Yourself »
Number.parseFloat("40.00");
Number.parseFloat(" 40 ");
Number.parseFloat("40 years");
Number.parseFloat("40H")
Number.parseFloat("H40");
Try it Yourself »

Description

The Number.parseFloat() method parses a value as a string and returns the first number.

Notes

If the first character cannot be converted, NaN is returned.

Leading and trailing spaces are ignored.

Only the first number found is returned.


Syntax

Number.parseFloat(value)

Parameters

Parameter Description
value Required.
The value to parse.

Return Value

Type Description
NumberNaN if no number is found.


Browser Support

Number.parseFloat() is an ECMAScript6 (ES6) feature.

ES6 (JavaScript 2015) is supported in all modern browsers since June 2017:

Chrome 51 Edge 15 Firefox 54 Safari 10 Opera 38
May 2016 Apr 2017 Jun 2017 Sep 2016 Jun 2016

Number.parseFloat() is not supported in Internet Explorer.


Copyright 1999-2023 by Refsnes Data. All Rights Reserved.