JavaScript Number.parseFloat() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Method

Definition

Number.parseFloat(string) reads a string (or value coerced to string) and returns a floating-point number. It keeps decimals, skips leading whitespace, and stops at the first character that is not part of a valid float. Same function as global parseFloat.

Pass the required arguments shown below. Check return values and browser support before you rely on the result.

Syntax

Call Number.parseFloat. Start with this line.

JavaScript
Number.parseFloat(string)
CallWhat it does
Number.parseFloat(string)Primary signature.
Number.parseFloat(...)Call with the arguments your case needs.

Built into JavaScript. Call Number.parseFloat(...) on the Number constructor — no import required.

Library declarations
JavaScript
Number.parseFloat(string)

Parameters

ParameterDescription
stringRequired. Value to parse (coerced to string)

Return Value

Return ValueDescription
*Float number, or NaN

JavaScript Examples

Example 1 — Decimals and Scientific Notation

Clean numeric strings parse to floating-point values.

JavaScript
console.log(Number.parseFloat("3.14"));     // 3.14
console.log(Number.parseFloat("15.9"));     // 15.9
console.log(Number.parseFloat("1.23e+2"));  // 123
console.log(Number.parseFloat("  -2.5"));   // -2.5
Try It Yourself

How It Works

  1. Keep decimals. "3.14" and "15.9" stay floats — not truncated.
  2. Scientific form. "1.23e+2" means 1.23 × 102 → 123.
  3. Leading spaces. Whitespace is skipped before reading the number.
  4. Sign allowed. An optional + or - is part of the float prefix.

Example 2 — Trailing Junk vs Number()

CSS-like suffixes are ignored after a valid float prefix.

JavaScript
console.log(Number.parseFloat("3.14px"));  // 3.14
console.log(Number("3.14px"));             // NaN

console.log(Number.parseFloat("15.9"));    // 15.9
console.log(Number.parseInt("15.9", 10));  // 15
Try It Yourself

How It Works

  1. Stop at junk. After 3.14, the p ends the parse — result stays 3.14.
  2. Number is strict. Number("3.14px") needs the whole string valid → NaN.
  3. vs parseInt. parseInt("15.9") stops at . and returns 15.
  4. When to use. Prefer parseFloat for measurements like "12.5em".

Example 3 — Failed Parse Returns NaN

If no valid float starts the string, the result is NaN — check it.

JavaScript
console.log(Number.parseFloat("hello"));  // NaN
console.log(Number.parseFloat(""));       // NaN
console.log(Number.isNaN(Number.parseFloat("hello")));  // true
console.log(Number.parseFloat("Infinity")); // Infinity
Try It Yourself

How It Works

  1. No prefix. "hello" has no leading float → NaN.
  2. Empty string. Same result — nothing to parse.
  3. Detect failure. Use Number.isNaN (not === NaN).
  4. Infinity text. "Infinity" parses to the number Infinity — pair with Number.isFinite if you need a finite value.

Browser & Runtime Support

Number.parseFloat() is part of ES2015 (as a Number static) and is Baseline Widely available. Global parseFloat has existed much longer.

✓ Baseline · ES2015

Number.parseFloat()

Supported in Chrome, Firefox, Safari, Edge, and Node.js. Safe for modern apps; global parseFloat works even in very old environments.

98% Modern browser support
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full support
Number.parseFloat Excellent

Bottom line: Use Number.parseFloat for new code. The global alias is identical and equally safe.

Frequently Asked Questions

Number.parseFloat(string) reads a string and returns a floating-point number. Example: Number.parseFloat("3.14") is 3.14; Number.parseFloat("3.14px") is also 3.14.
Yes. Call it on Number itself: Number.parseFloat(s). It is the same function as the global parseFloat — Number.parseFloat === parseFloat is true.
parseFloat keeps the fractional part: Number.parseFloat("15.9") is 15.9. parseInt stops at the decimal point: Number.parseInt("15.9") is 15. parseFloat has no radix parameter.
Parsing stops at the first character that is not part of a valid float. Number.parseFloat("3.14px") returns 3.14. If nothing valid is found at the start, the result is NaN.
Number("3.14px") is NaN because the whole string must be a valid number. Number.parseFloat("3.14px") is 3.14 because it reads a leading float prefix.
It is Baseline Widely available (ES2015) and supported in every modern browser and Node.js.

Next: Number Properties

Explore Number constants like MAX_VALUE, EPSILON, and MAX_SAFE_INTEGER.

Number properties →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

9 people found this page helpful