added float parse support .

This commit is contained in:
Zero Fanker 2024-04-05 00:20:16 -04:00
parent d4a58864ff
commit 7d80e89afb
3 changed files with 112 additions and 77 deletions

View file

@ -28,6 +28,21 @@ public:
}
return def;
}
static double StringToDouble(const CString& str, double def)
{
double ret = 0;
if (sscanf_s(str, "%lf", &ret) == 1) {
if (strchr(str, '%')) {
ret *= 0.01;
}
return ret;
}
return def;
}
static float StringToFloat(const CString& str, float def)
{
return static_cast<float>(StringToDouble(str, def));
}
template<typename T>
static CString ToString(const T& origin);// { static_assert(false, "T must have specialized implementations!"); }
@ -38,4 +53,12 @@ public:
static CString result[] = { "no", "yes" };
return result[origin];
}
template<>
static CString ToString<int>(const int& origin)
{
char buffer[0x100];
_itoa_s(origin, buffer, 10);
return buffer;
}
};