Back
Is there a neater way for getting the length of an int than this method?
int length = String.valueOf(1000).length();
Your String-based clarification is absolutely OK, there is zero "un-neat" regarding it. You have to understand that mathematically, numbers don't have a length, nor do they have digits. Length and digits are both parts of a physical representation of a number in a specific base, i.e. a String.
A logarithm-based answer does (some of) the identical things the String-based one does internally, and apparently does so (insignificantly) ready because it only produces the length and overlooks the digits. But I wouldn't count it more obvious in intent - and that's the common major factor.
31k questions
32.8k answers
501 comments
693 users