I'm trying to check if a given number is 2 or 3 digit after the decimal point, I tried a few methods but non but one was good: the first one is -
bool Is2DecimalPlaces(double num) {
double value = num * 100;
auto ans = (value == std::floor(value));
return ans;
}
but on input 10.12
and 10.13
it gives the wrong answer,
I tried using decimal::decimal64
bool Is2DecimalPlaceString(double num) {
std::decimal::decimal64 var(num);
return std::decimal::decimal64(std::floor(num * 100)) == (var *= 100);
}
also not working
the only method that works every time is co convert to string and check if the third place after the decimal point in '0'
but it's not very efficient.
tried using this answer from here with no luck
this is my test case