🔢 Converts a value to a finite number.
Syntax
TypeScript
import { toNum } from '@opentf/std'; toNum(val: unknown): number
Parameters
val: The value to convert.
Returns
The converted number if the value is a valid numeric representation; otherwise, NaN.
Supports numeric separators in valid positions. Invalid separator placements such as 1_e2 or 1._5 return NaN.
Examples
TypeScript
toNum(1) //=> 1 toNum('1.3') //=> 1.3 toNum('1_000') //=> 1000 (Supports numeric separators) toNum('0xF') //=> 15 (Supports hex strings) toNum('0xF_F') //=> 255 (Supports separated hex strings) toNum(Infinity) //=> NaN toNum('abc') //=> NaN