AutoRpa/rpa_selection/util.py

34 lines
720 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from __future__ import annotations
from typing import Any
def normalize_text(value: Any) -> str:
if value is None:
return ""
return str(value).strip()
def parse_int_or_none(value: Any) -> int | None:
text = normalize_text(value)
if text == "":
return None
try:
return int(float(text))
except ValueError:
return None
def parse_float_or_none(value: Any) -> float | None:
text = normalize_text(value)
if text == "":
return None
try:
return float(text)
except ValueError:
cleaned = text.replace(",", "").replace(",", "")
try:
return float(cleaned)
except ValueError:
return None