is_str_float

pyrcs.utils.is_str_float(x, finite_only=False)[source]

Checks if a string represents and can be converted to a finite float value.

This function attempts to convert the input to a float. It returns False for non-numeric strings, None inputs, or special floating point values like NaN or Infinity (optional).

Parameters:
  • x (str | Any) – String-type data or any object that can be converted to float.

  • finite_only (bool) – Whether to return False for special values such as NaN and Infinity; defaults to False.

Returns:

True if the string represents a valid finite number, False otherwise.

Return type:

bool

Examples:

>>> from pyrcs.utils import is_str_float
>>> is_str_float('')
False
>>> is_str_float('a')
False
>>> is_str_float('1')
True
>>> is_str_float('1.1')
True
>>> is_str_float('nan', finite_only=True)
False
>>> is_str_float('inf')
True