How can I count the digits in an integer without a string cast?

This should do it:

int length = (number ==0) ? 1 : (int)Math.log10(number) + 1;

Leave a Comment