The following snippet uses log() to find the number of digits in the integer x. The result is 5.

int x = 12345;
int length = (int)(Math.log10(x) + 1);

Source: http://stackoverflow.com/questions/1306727/way-to-get-number-of-digits-in-an-int