Relawan kami belum menerjemahkan artikel ini ke bahasa Bahasa Indonesia. Bergabunglah dan bantu kami menyelesaikannya!
Anda juga dapat membaca artikel ini dalam English (US).

The parseFloat() function parses an argument and returns a floating point number.




The value you want to parse.

Return value

A floating point number parsed from the given value. If the value cannot be converted to a number, NaN is returned.


parseFloat is a top-level function and is not associated with any object.

parseFloat parses its argument, and returns a floating point number. If it encounters a character other than a sign (+ or -), numeral (0-9), a decimal point, or an exponent, it returns the value up to that point and ignores that character and all succeeding characters. Leading and trailing spaces are allowed. Consider Number(value) for stricter parsing, which converts to NaN for values with such invalid characters regardless of position.

If the value is a string and the first character cannot be converted to a number, parseFloat also returns NaN.

For arithmetic purposes, the NaN value is not a number in any radix. You can call the isNaN function to determine if the result of parseFloat is NaN. If NaN is passed on to arithmetic operations, the operation results will also be NaN.

parseFloat can also parse and return the value Infinity. You can use the isFinite function to determine if the result is a finite number (not Infinity, -Infinity, or NaN).

parseFloat is also able to parse an object if it has a toString or valueOf method defined. The returned value is the same as if parseFloat had been called on the result of calling that method.

parseFloat converts a BigInt to a Number and loses precision in the process because trailing non-numeric values, including "n", are discarded.


parseFloat returning a number

The following examples all return 3.14:

parseFloat('3.14more non-digit characters');

var foo = Object.create(null);
foo.toString = function () { return "3.14"; };

parseFloat returning NaN

The following example returns NaN:


parseFloat and BigInt

// 900719925474099300


Specification Status Comment
ECMAScript 1st Edition (ECMA-262) Standard Initial definition.
ECMAScript 5.1 (ECMA-262)
The definition of 'parseFloat' in that specification.
ECMAScript 2015 (6th Edition, ECMA-262)
The definition of 'parseFloat' in that specification.
ECMAScript Latest Draft (ECMA-262)
The definition of 'parseFloat' in that specification.

Browser compatibility

Update compatibility data on GitHub
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung InternetNode.js
parseFloatChrome Full support YesEdge Full support YesFirefox Full support 1IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support Yes


Full support  
Full support

See also