Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/internal/reader_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,18 @@ Value jsonToValue(nlohmann::json value)
{
if (value.is_string())
return value.get<std::string>();
else if (value.is_number())
return std::stod(value.dump());
else if (value.is_boolean())
else if (value.is_number()) {
// Set locale to C to avoid conversion issues
std::string oldLocale = std::setlocale(LC_NUMERIC, nullptr);
std::setlocale(LC_NUMERIC, "C");

double converted = std::stod(value.dump());

// Restore old locale
std::setlocale(LC_NUMERIC, oldLocale.c_str());

return converted;
} else if (value.is_boolean())
return value.get<bool>();
else
return value.dump();
Expand Down
18 changes: 18 additions & 0 deletions test/load_project/load_project_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -709,3 +709,21 @@ TEST(LoadProjectTest, LoadNullDimensionMonitor)
Project p(name);
ASSERT_TRUE(p.load());
}

TEST(LoadProjectTest, LoadDoubleValue)
{
// Regtest for #437
std::string oldLocale = std::setlocale(LC_NUMERIC, nullptr);
std::setlocale(LC_NUMERIC, "sk_SK.UTF-8");

std::string name = "regtest_projects/437_load_double_values.sb3";
Project p(name);
ASSERT_TRUE(p.load());

auto stage = p.engine()->stage();
ASSERT_TRUE(stage);
ASSERT_VAR(stage, "test");
ASSERT_EQ(GET_VAR(stage, "test")->value().toDouble(), 5.6654);

std::setlocale(LC_NUMERIC, oldLocale.c_str());
}
Binary file added test/regtest_projects/437_load_double_values.sb3
Binary file not shown.