Skip to content

Error in convertFromString<double> #120

@moritzknaust

Description

@moritzknaust

I found a strange error in the convertFromString method. If I use the behaviortree in a rqt-gui plugin, the conversion from string to double is wrong. For example "1.23" is converted to 1 instead of 1.23. This only happens if I use a rqt-gui plugin. When I use the behaviortree in a normal ROS node everything works fine.

I think this error is related to this topic: https://www.reddit.com/r/cpp/comments/2e68nd/stdstod_is_locale_dependant_but_the_docs_does_not/
Maybe Qt changes the used locale to another value, but I am not sure about this.

I have fixed it by using std::istringstream for the conversion instead of std::stod like it is explained in the post. My new version of convertFromString in basic_types.cpp is now the following:

template <>
double convertFromString<double>(StringView str)
{
    std::istringstream iss(str.data());
    iss.imbue(std::locale("C"));
    double temp;
    iss >> temp;
    return temp;
}

This error is very confusing and generates really unexpected behaviors, so can you please fix it? But all in all I really like the library!

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions