How can I count the digits in an integer without a string cast? May 15, 2023 by Tarik Billa This should do it: int length = (number ==0) ? 1 : (int)Math.log10(number) + 1; More Related Contents: How can I pad an integer with zeros on the left? Python datetime formatting without zero-padding Zero pad numpy array Formatting a date in R without leading zeros