libb.numify
- numify(val, to=<class 'float'>)[source]
Convert value to numeric type, handling common formatting.
Handles None values, already numeric values, and string formatting including whitespace, commas, parentheses (negative), and percentages.
- Parameters:
val – Value to convert.
to (type) – Target type (default: float).
- Returns:
Converted value or None if conversion fails.
Example:
>>> numify('1,234.56') 1234.56 >>> numify('(100)', to=int) -100 >>> numify('50%') 50.0 >>> numify(None) >>> numify('')