How do I determine the number of digits of an integer in C?

c, math

Solution

floor (log10 (abs (x))) + 1

http://en.wikipedia.org/wiki/Logarithm

Problem

for instance, ``` n = 3432, result 4 n = 45, result 2 n = 33215, result 5 n = -357, result 3 ``` I guess I could just turn it into a string then get the length of the string but that seems convoluted and hack-y.

Original source

Related problems