I have a requirement where i need to find the number of digits in a integer. I have searched it and got some tricks. But i also developed a my own trick. I just want to know if it is correct way to know the number of digits in the integer.
for (int i = 1; i < 11; i++) {
if (Math.abs(number) < (j = Math.pow(10, i))) {
System.out.println("Number of Digits : "+i);
break;
}
}
I took 11 as limit because max integer is of 11 digits. Please let me know if it is a correct way or not.
please note that I dont have an option to use any string api.