INNER CODE UNIT · Python
force_decimal_validator
DogsTailFarmer/martin-binance · martin_binance/backup.py:242
def force_decimal_validator(v: Any) -> Any:
"""Forces string/number conversion to Decimal when reading state, respects None."""
if v is None or v == "None":
return None
try:
return Decimal(str(v))
except (ValueError, InvalidOperation):
return Decimal('0')
def force_int_validator(v: Any) -> Any:
"""Safely converts float/string timestamps to integer by dropping fractions."""
if v is None or v == "None":
return None
try:
return int(float(v))
except (ValueError, TypeError):
return 0