mirror of
https://github.com/toss/es-toolkit.git
synced 2024-12-01 02:33:54 +03:00
847 B
847 B
toNumber
::: info
This function is only available in es-toolkit/compat
for compatibility reasons. It either has alternative native JavaScript APIs or isn’t fully optimized yet.
When imported from es-toolkit/compat
, it behaves exactly like lodash and provides the same functionalities, as detailed here.
:::
Converts value
to a number.
Unlike Number()
, this function returns NaN
for symbols.
Signature
function toNumber(value?: unknown): number;
Parameters
value
(unknown
): The value to convert.
Returns
(number
): The converted number.
Examples
toNumber(3.2); // => 3.2
toNumber(Number.MIN_VALUE); // => 5e-324
toNumber(Infinity); // => Infinity
toNumber('3.2'); // => 3.2
toNumber(Symbol.iterator); // => NaN
toNumber(NaN); // => NaN