This is already defined in the language, no need to calculate.
The number of base 10 digits, is std::numeric_limits::digits10, where T is int, unsigned, long, long long, float, double, long double, etc.
There was a trivial change at c++ 11, to define if this was an int type or define.
note: The number of bits to store is std::numeric_limits::digits.
So, to get the digits to display an unsigned you would use:
#include limits
short displayDigitsBase10 = std::numeric_limits<unsigned>::digits10;
Here is one link.
https://en.cppreference.com/w/cpp/types/numeric_limits/digits10