metadata
title: Number.parseFloat()
short-title: parseFloat()
slug: Web/JavaScript/Reference/Global_Objects/Number/parseFloat
page-type: javascript-static-method
browser-compat: javascript.builtins.Number.parseFloat
sidebar: jsref
The Number.parseFloat() static method parses an argument and returns a floating point number. If a number cannot be parsed from the argument, it returns {{jsxref("NaN")}}.
{{InteractiveExample("JavaScript Demo: Number.parseFloat()")}}
function circumference(r) {
if (Number.isNaN(Number.parseFloat(r))) {
return 0;
}
return parseFloat(r) * 2.0 * Math.PI;
}
console.log(circumference("4.567abcdefgh"));
// Expected output: 28.695307297889173
console.log(circumference("abcdefgh"));
// Expected output: 0
Syntax
Number.parseFloat(string)
Parameters
string- : The value to parse, coerced to a string. Leading {{Glossary("whitespace")}} in this argument is ignored.
Return value
A floating point number parsed from the given string.
Or {{jsxref("NaN")}} when the first non-whitespace character cannot be converted to a number.
Examples
Number.parseFloat vs. parseFloat
This method has the same functionality as the global {{jsxref("parseFloat()")}} function:
Number.parseFloat === parseFloat; // true
Its purpose is modularization of globals.
See {{jsxref("parseFloat()")}} for more detail and examples.
Specifications
{{Specifications}}
Browser compatibility
{{Compat}}
See also
- Polyfill of
Number.parseFloatincore-js - es-shims polyfill of
Number.parseFloat - {{jsxref("Number")}}
- {{jsxref("parseFloat()")}}