Lodash _.toFinite() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Lang

Definition

Converts value to a finite number. Invalid conversions become 0; ±Infinity clamp to ±Number.MAX_VALUE. Part of Lodash 4.x Lang (since 4.12.0).

Pass the value you want to inspect or convert. Read the return type carefully before you use the result.

Syntax

Call _.toFinite. Start with this line.

Lodash
_.toFinite(value)
CallWhat it does
_.toFinite(value)Primary signature.

Prefer import toFinite from "lodash/toFinite" when you want a smaller bundle.

Library declarations
Lodash
_.toFinite(value)

Parameters

ParameterDescription
valueRequired. Any value to convert

Return Value

Return ValueDescription
*Finite number (never NaN / Infinity)

Lodash Examples

Example 1 — Official: Number and Numeric String

Finite values convert as expected; decimals are kept.

Lodash
_.toFinite(3.2);
// → 3.2

_.toFinite("3.2");
// → 3.2
Try It Yourself

How It Works

  1. Number. 3.2 is already finite → returned unchanged.
  2. String. "3.2" parses via Lodash’s number path.
  3. Decimals. Unlike toInteger, the fractional part stays.
  4. Whitespace. Strings like " 3.2 " also work (trimmed).

Example 2 — Official: Clamp Infinity

Never return Infinity — clamp to the largest finite double.

Lodash
_.toFinite(Infinity);
// → 1.7976931348623157e+308

_.toFinite(Infinity) === Number.MAX_VALUE;
// → true
Try It Yourself

How It Works

  1. Detect. Input is positive Infinity.
  2. Clamp. Replace with Number.MAX_VALUE.
  3. Safe math. Result is finite — usable in further calculations.
  4. vs toNumber. _.toNumber(Infinity) would still be Infinity.

Example 3 — Official: Number.MIN_VALUE

Tiny positive finite values are left alone.

Lodash
_.toFinite(Number.MIN_VALUE);
// → 5e-324
Try It Yourself

How It Works

  1. Already finite. No clamp needed.
  2. Keep. Returns the same tiny positive number.
  3. Not zero. Do not confuse with underflow to 0 in other APIs.
  4. Official. Matches the Lodash docs example.

Example 4 — Invalid Values Become 0

Safer default than native Number(), which often yields NaN.

Lodash
_.toFinite(NaN);
// → 0

_.toFinite(null);
// → 0

_.toFinite("abc");
// → 0

Number("abc");
// → NaN
Try It Yourself

How It Works

  1. Parse. Non-numeric input becomes NaN internally.
  2. Guard. toFinite maps that NaN to 0.
  3. null. Treated as empty/zero path → 0.
  4. Contrast. Native Number("abc") stays NaN.

Example 5 — Negative Infinity and Overflow Strings

Both signs clamp; huge numeric strings that overflow also land on MAX_VALUE.

Lodash
_.toFinite(-Infinity);
// → -1.7976931348623157e+308

_.toFinite(-Infinity) === -Number.MAX_VALUE;
// → true

_.toFinite("1e309");
// → 1.7976931348623157e+308
Try It Yourself

How It Works

  1. -Infinity. Clamps to -Number.MAX_VALUE.
  2. Overflow string. "1e309" parses to Infinity, then clamps.
  3. Symmetric. Positive and negative extremes both stay finite.
  4. Use case. Harden user input before charts, averages, or clamps.

Browser & Runtime Support

_.toFinite is a Lodash 4.x Lang helper (since 4.12.0). It runs anywhere Lodash runs — modern browsers (CDN or bundle) and Node.js / Bun / Deno with npm install lodash. Native Number() does not clamp Infinity or map bad strings to 0 the same way.

✓ Stable · Lodash 4.x

_.toFinite()

Available in [email protected] full builds and the lodash/toFinite modular import. Works in evergreen browsers and current Node LTS when Lodash is installed.

100% With Lodash 4.x
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
_.toFinite Lodash 4.12+

Bottom line: Safe for production once Lodash is loaded. Prefer import toFinite from "lodash/toFinite" for smaller builds. Ideal for sanitizing form numbers, chart inputs, and math helpers that must stay finite.

Frequently Asked Questions

_.toFinite(value) converts value to a finite number. Invalid or empty-like values become 0. ±Infinity clamp to ±Number.MAX_VALUE.
toNumber can return NaN or Infinity. toFinite never returns those — it maps them to 0 or ±Number.MAX_VALUE.
toFinite keeps decimals (3.2 stays 3.2). toInteger truncates toward zero after converting (3.2 → 3).
It stays Number.MIN_VALUE (about 5e-324) — already finite, so no clamp.
No. Passing a BigInt throws (cannot convert BigInt to number). Convert explicitly first if you must.
Use import toFinite from "lodash/toFinite" or require("lodash/toFinite") for tree-shaking. Full build: import _ from "lodash" then _.toFinite.

Next: _.toInteger()

Convert a value to an integer — truncating after the finite conversion.

_.toInteger() tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

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.

10 people found this page helpful