Toolbox-XToolbox-X

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 | undefined

Parameters

  • num (unknown): A value that might be a number or a numeric string.

Return Value

  • number | undefined: A normalized number, or undefined if 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 isNumber and isNumericString internally to validate inputs.

See Also

Last updated: Mon, Jun 15, 2026 11:04:47AM (UTC)

On this page