文章目录
Method 1
int countDecimalPlaces(double num)
{
std::string str = std::to_string(value);
size_t decimalPos = str.find(".");
if (decimalPos == std::string::npos) {
return 0;
}
int decimalPlaces = 0;
for (size_t i = str.length()-1; i >= decimalPos + 1; --i) {
if (str[i] == '0') {
continue;
} else {
return i-decimalPos;
}
}
return decimalPlaces;
}