79305794

Date: 2024-12-24 14:21:33
Score: 0.5
Natty:
Report link

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

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Unregistered user (0.5):
  • Low reputation (1):
Posted by: Norman Bo Graham