This should work if y
is non-negative. For negative y
, the result if off-by-one. Fix it yourself if needed.
#include <iostream>
#include <cmath>
int main()
{
double x = 3.44828e+026;
int y = (int)log10(x);
std::cout << y << std::endl;
return 0;
}
Output: 26