def count_digits_string(value: int) -> int:
"""
Counts digits by converting the number to a string.
This approach is clear, safe, and widely used in everyday Python code.
"""
text = str(value)
# If negative, ignore the leading '-'
if text.startswith("-"):
return len(text) - 1
return len(text)
number = -12345
digits = count_digits_string(number)
print("Number:", number)
print("Digit count (String method):", digits)
"""
run:
Number: -12345
Digit count (String method): 5
"""