JavaScript Number parseFloat() Method

Beginner
⏱️ 10 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Static method

What You’ll Learn

Number.parseFloat() is a static method on Number (same API as MDN Number.parseFloat). Call Number.parseFloat(string) — not on a number instance. It turns text into a floating-point number and keeps decimals. This tutorial covers syntax, junk suffixes, scientific notation, five examples, and try-it labs.

01

Call on

Number only

02

Returns

float / NaN

03

Keeps

decimals

04

Same as

global parseFloat

05

Stops at

first bad char

06

Baseline

Everywhere

Introduction

Prices, ratings, and CSS lengths often arrive as text — "3.14", "19.99", or "4.5rem". Number.parseFloat() reads the leading floating-point number from that text.

It is the same function as the global parseFloat ((Number.parseFloat === parseFloat). The Number. form keeps number helpers together on one object.

💡
Static Method

Static methods belong to Number itself. Always write Number.parseFloat(s). There is no (5).parseFloat() on Number.prototype.

This page is part of JavaScript Number Methods. Related tools include Number.parseInt() for integers, toFixed() for display decimals, and Number.isNaN() to check failed parses.

Understanding the parseFloat() Method

Call Number.parseFloat(string). The engine:

  • Coerces the argument to a string and skips leading whitespace.
  • Reads an optional sign, digits, optional decimal point, and optional exponent (e / E).
  • Stops at the first character that is not part of that float (so "3.14px" still yields 3.14).
  • Returns NaN if the first non-whitespace character cannot start a number.

📝 Syntax

General form of the static method Number.parseFloat:

JavaScript
Number.parseFloat(string)

Parameters

  • string (any) — value to parse (coerced to string). Leading whitespace is ignored.

Return value

A floating-point number, or NaN:

InputReturns
Number.parseFloat("3.14")3.14
Number.parseFloat("3.14px")3.14
Number.parseFloat("1.23e+2")123
Number.parseFloat("4.567abcdefgh")4.567
Number.parseFloat("hello")NaN

Exceptions

  • None for normal calls — bad input yields NaN rather than a thrown error.

Common patterns

JavaScript
Number.parseFloat("3.14");              // 3.14
Number.parseFloat("3.14px");            // 3.14
Number.parseFloat("1.23e+2");           // 123
Number.parseFloat("4.567abcdefgh");     // 4.567
Number.parseFloat("hello");             // NaN
Number.parseFloat === parseFloat;       // true

⚡ Quick Reference

GoalCode
Decimal float from textNumber.parseFloat(s)
CSS size with decimalsNumber.parseFloat("1.5rem")
Scientific notationNumber.parseFloat("1.5e3")
Check failed parseNumber.isNaN(Number.parseFloat(s))
Integers only (truncate)Number.parseInt(s, 10)
Strict whole-string numberNumber(s) (not parseFloat)

🔍 At a Glance

Four facts to remember about Number.parseFloat().

Kind
static

Call on Number, not instances

Returns
number

Float or NaN

Decimals
kept

Unlike parseInt

Alias
parseFloat

Same as the global function

📋 Number.parseFloat() vs Number.parseInt() vs Number()

Number.parseFloat(s)Number.parseInt(s, 10)Number(s)
"3.14px"3.143NaN
"15.9"15.91515.9
"1.23e+2"1231 (stops at .)123
Radix / baseNoYes (2–36)No
Global twinparseFloatparseInt

Examples Gallery

Examples follow MDN / parseFloat patterns. Use View Output or Try It Yourself for each case.

📚 Getting Started

Plain floats and strings with trailing units.

Example 1 — Decimal String

Parse a simple floating-point string.

JavaScript
Number.parseFloat("3.14");  // 3.14
Try It Yourself

How It Works

Digits and the decimal point are kept. Compare with Number.parseInt("3.14"), which returns 3.

Example 2 — Trailing Junk

Useful for CSS-like values such as "3.14px" or "1.5rem".

JavaScript
Number.parseFloat("3.14px");  // 3.14
Try It Yourself

How It Works

Parsing stops at p. Compare with Number("3.14px"), which is NaN.

📈 Practical Patterns

Exponents, MDN-style helpers, and failed parses.

Example 3 — Scientific Notation

Exponent markers e / E are part of the float.

JavaScript
Number.parseFloat("1.23e+2");  // 123
Try It Yourself

How It Works

1.23 × 102 becomes 123. Pair with toExponential() for the reverse display form.

Example 4 — MDN Circumference Helper

Parse a radius string (junk allowed), guard with isNaN, then compute.

JavaScript
function circumference(r) {
  if (Number.isNaN(Number.parseFloat(r))) {
    return 0;
  }
  return Number.parseFloat(r) * 2.0 * Math.PI;
}

circumference("4.567abcdefgh");  // ≈ 28.695307297889173
Try It Yourself

How It Works

MDN-style pattern: parse first, reject NaN, then use the float in math. "abcdefgh" would return 0.

Example 5 — Failed Parse

No leading digits means NaN.

JavaScript
Number.parseFloat("hello");  // NaN
Try It Yourself

How It Works

Detect failure with Number.isNaN(): Number.isNaN(Number.parseFloat("hello")) is true.

🚀 Common Use Cases

  • Form inputs — prices, ratings, and measurements typed as text.
  • CSS / DOM sizes — pull the float out of "1.5rem" or "12.5px".
  • Science / sensors — read values that may include scientific notation.
  • Tolerant parsers — accept trailing units or labels without failing.
  • Guarded math — check Number.isNaN before multiplying (MDN circumference pattern).
  • Not for bases — use Number.parseInt when radix 2–36 matters.

🧠 How Number.parseFloat() Reads a String

1

Coerce to string

Skip leading whitespace.

Input
2

Read float syntax

Sign, digits, decimal, optional exponent.

Scan
3

Stop early

First invalid character ends the parse.

Boundary
4

Return float or NaN

Success yields a number; failure yields NaN.

📝 Notes

  • This is a static method — use Number.parseFloat(s) only.
  • Number.parseFloat === parseFloat — same built-in function.
  • There is no radix parameter — unlike Number.parseInt.
  • Keeps the fractional part: Number.parseFloat("15.9") is 15.9.
  • Accepts scientific notation such as "1.5e3".
  • Check failures with Number.isNaN(), not === NaN.

Browser & Runtime Support

Number.parseFloat() is Baseline Widely available — part of ES2015 and supported in every modern browser and Node.js.

Baseline · Widely available

Number.parseFloat()

Safe for production everywhere. Same behavior as global parseFloat, grouped under Number.

100% Universal 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 when decimals matter. Use Number.parseInt with an explicit radix for integers. Use Number() when the entire string must be a valid numeric literal.

Conclusion

Number.parseFloat() is the static, modular way to turn text into floating-point numbers — keeping decimals, accepting exponents, and tolerating suffixes like px.

Continue with parseInt() for integers, toFixed() for display rounding, Number.isNaN() for failed parses, or return to the Number methods hub.

💡 Best Practices

✅ Do

  • Call Number.parseFloat(s) on the constructor
  • Use it when the fractional part matters
  • Check Number.isNaN(result) after parsing user input
  • Use it for CSS sizes with decimals (rem, em, px)
  • Pair with toFixed() or toPrecision() for display

❌ Don’t

  • Write (5).parseFloat() — that is not a Number method
  • Expect a radix — there is none on parseFloat
  • Use it when you need binary/hex parsing (parseInt)
  • Use it when the whole string must be a pure number (Number())
  • Compare the result with === NaN

Key Takeaways

Knowledge Unlocked

Five things to remember about Number.parseFloat()

Static string-to-float parsing that keeps decimals.

5
Core concepts
📝 02

Returns

number

Result
. 03

Decimals

kept

Float
px 04

Stops

early

Suffix
05

Alias

parseFloat

Same

❓ 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.
Did you know?

Number.parseFloat was added so number-related helpers live on Number, but it is literally the same function object as the global parseFloatNumber.parseFloat === parseFloat is true in modern engines.

More Number Methods

Return to the hub for instance and static Number tutorials.

Number methods hub →

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.

8 people found this page helpful