Created
March 26, 2015 00:03
-
-
Save mbchoa/d29b3c9a4c6643362d99 to your computer and use it in GitHub Desktop.
Find the number of digits in an integer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for(long long int temp = number; temp >= 1;) | |
{ | |
temp/=10; | |
decimalPlaces++; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String s = new Integer(t).toString(); | |
int len = s.length(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int digits = (int)(Math.log(integer) / Math.log(10) + 1); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment