Last active
July 22, 2020 21:10
-
-
Save TheSeanLavery/b31ed132f0ab2d61bee2fdd36f0eda86 to your computer and use it in GitHub Desktop.
Get the number of digits in an Int
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
public static int GetNumDigitsOfInt(int v) { | |
if(v < 0) { | |
throw new ArgumentOutOfRangeException(); | |
} | |
if(v == 0) { | |
return 1; | |
} | |
return (int)Math.Log10(v) +1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment