Number.parseFloat
Parses an argument and returns a floating-point number
Syntax
Number.parseFloat(string)Parameters
| Parameter | Type | Description |
|---|---|---|
| string | string | The value to parse |
Return Value
A floating-point number, or NaN if parsing fails
Examples
console.log(Number.parseFloat('3.14')); // 3.14
console.log(Number.parseFloat('314e-2')); // 3.14console.log(Number.parseFloat('3.14some text')); // 3.14
console.log(Number.parseFloat('text')); // NaNconst prices = ['$9.99', '$14.50', '$3.01'];
const nums = prices.map(p => Number.parseFloat(p.slice(1)));
console.log(nums); // [9.99, 14.5, 3.01]Understanding Number.parseFloat
The Number.parseFloat method in JavaScript parses an argument and returns a floating-point number. It belongs to the Number object and is one of the most widely used methods for working with number values in modern JavaScript and TypeScript applications.
The method signature is Number.parseFloat(string). It accepts 1 parameter: string. When called, it returns a floating-point number, or nan if parsing fails. Understanding when and how to use parseFloat() helps you write more expressive, readable code.
Common use cases for Number.parseFloat include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like number-parseint, number-isnan, number-isfinite, enabling you to chain operations together for complex data manipulation pipelines.
Browser support for Number.parseFloat is excellent across all modern browsers including Chrome, Firefox, Safari, and Edge. It is also fully supported in Node.js and Deno. For older environments, transpilation with Babel or a polyfill may be needed.
Browser Compatibility
Supported in all modern browsers (Chrome, Firefox, Safari, Edge) and Node.js. Part of the ECMAScript standard.
Related Methods
Number.parseIntParses a string argument and returns an integer of the specified radix
Number.isNaNDetermines whether the passed value is NaN and its type is Number, providing a more robust version of the original global isNaN()
Number.isFiniteDetermines whether the passed value is a finite number — not Infinity, -Infinity, or NaN
More Number Methods
Other methods in the Number object
Related Tools
More Number Methods
Explore JavaScript Methods
Browse our complete reference of 410 JavaScript methods with syntax, examples, and explanations.