Normalize Numeric Value
Safely converts a number or numeric string to a number.
normalizeNumber
The normalizeNumber function accepts either a number or a numeric string and safely converts it to a number. If the input is not a valid number or a numeric string, it returns undefined.
Note
This is useful when accepting input from forms, query parameters, or external data sources where values might be stringified numbers.
Function Signature
function normalizeNumber(num: unknown): number | undefinedParameters
num(unknown): A value that might be a number or a numeric string.
Return Value
number | undefined: A normalized number, orundefinedif the input is not a valid number or numeric string.
Example Usage
playground.ts
Notes
- Automatically handles both integers and floating-point numeric strings.
- Uses
isNumberandisNumericStringinternally to validate inputs.
See Also
- isNumber - Guard check for basic numbers.
- isNumericString - Guard check for numeric strings.
Last updated: Mon, Jun 15, 2026 11:04:47AM (UTC)
