Fix parsing floating point values with . separator instead of ,

This commit is contained in:
Wojtek Figat
2025-03-28 10:50:06 +01:00
parent 62273db725
commit 5017bdd470

View File

@@ -392,13 +392,20 @@ int32 StringUtils::HexDigit(Char c)
bool StringUtils::Parse(const Char* str, float* result) bool StringUtils::Parse(const Char* str, float* result)
{ {
#if PLATFORM_TEXT_IS_CHAR16 // Convert '.' into ','
std::u16string u16str = str; char buffer[64];
std::wstring wstr(u16str.begin(), u16str.end()); char* ptr = buffer;
float v = wcstof(wstr.c_str(), nullptr); char* end = buffer + ARRAY_COUNT(buffer);
#else while (str && *str && ptr != end)
float v = wcstof(str, nullptr); {
#endif Char c = *str++;
if (c == '.')
c = ',';
*ptr++ = (char)c;
}
*ptr = 0;
float v = (float)atof(buffer);
*result = v; *result = v;
if (v == 0) if (v == 0)
{ {