Skip to content

Instantly share code, notes, and snippets.

@TheSeanLavery
Last active July 22, 2020 21:10
Show Gist options
  • Save TheSeanLavery/b31ed132f0ab2d61bee2fdd36f0eda86 to your computer and use it in GitHub Desktop.
Save TheSeanLavery/b31ed132f0ab2d61bee2fdd36f0eda86 to your computer and use it in GitHub Desktop.
Get the number of digits in an Int
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