Converts value to a number — the raw coercion under _.toFinite, _.toInteger, and friends. Can return NaN or ±Infinity. Part of Lodash 4.x Lang (since 4.0.0).
Pass the value you want to inspect or convert. Read the return type carefully before you use the result.
Syntax
Call _.toNumber. Start with this line.
Lodash
_.toNumber(value)
Call
What it does
_.toNumber(value)
Primary signature.
Prefer import toNumber from "lodash/toNumber" when you want a smaller bundle.
Bad strings. Both parse to NaN first; only toFinite maps to 0.
Choose. Diagnostics → toNumber; math defaults → toFinite.
Compatibility
Browser & Runtime Support
_.toNumber is a Lodash 4.x Lang helper (since 4.0.0). It runs anywhere Lodash runs — modern browsers (CDN or bundle) and Node.js / Bun / Deno with npm install lodash. Closest natives are Number(value) / unary +; Lodash adds consistent string trimming, literal-prefix parsing, and the valueOf object path.
✓ Stable · Lodash 4.x
_.toNumber()
Available in [email protected] full builds and the lodash/toNumber modular import. Works in evergreen browsers and current Node LTS when Lodash is installed.
100%With Lodash 4.x
Google ChromeSupported · Desktop & Mobile
Full support
Mozilla FirefoxSupported · Desktop & Mobile
Full support
Apple SafariSupported · macOS & iOS
Full support
Microsoft EdgeSupported · Chromium
Full support
Internet ExplorerNo native support · Use a polyfill
Polyfill
OperaSupported · Modern versions
Full support
Samsung InternetSupported · Android
Full support
BunSupported · JavaScript runtime
Supported
DenoSupported · JavaScript runtime
Supported
Node.jsSupported · Server runtime
Supported
Android WebViewSupported · Modern WebView
Full support
_.toNumberLodash 4.x+
Bottom line: Safe for production once Lodash is loaded. Prefer import toNumber from "lodash/toNumber" for smaller builds. Reach for toFinite when you need a soft, always-finite result.
Frequently Asked Questions
_.toNumber(value) converts value to a JavaScript number. Unlike toFinite, it can return NaN or ±Infinity.
No. undefined → NaN. null → 0. If you want a soft 0 fallback, use _.toFinite.
Very similar for most inputs. Lodash trims strings and carefully parses 0x / 0b / 0o prefixes; objects go through valueOf first.
toNumber keeps NaN and Infinity. toFinite maps those to 0 and ±Number.MAX_VALUE.
Symbol becomes NaN. BigInt throws — convert explicitly first if you must.
Use import toNumber from "lodash/toNumber" or require("lodash/toNumber") for tree-shaking. Full build: import _ from "lodash" then _.toNumber.