Skip to main content

str_as_float

Converts a string to a floating-point number, returning None if the conversion fails or if the input is not a string.

def str_as_float(
s: str
) - > float

Converts a string representation of a number into a float value. Use this to safely parse numeric strings from external inputs or configuration files.

Parameters

NameTypeDescription
sstrThe string value containing a numeric representation to be converted.

Returns

TypeDescription
floatThe numeric float representation of the input string.