def count_digits_string(value)
# Convert the number to a string
text = value.to_s
# If negative, ignore the leading '-'
if text.start_with?("-")
return text.length - 1
end
text.length
end
number = -12345
digits = count_digits_string(number)
puts "Number: #{number}"
puts "Digit count (String method): #{digits}"
=begin
run:
Number: -12345
Digit count (String method): 5
=end