Solved std::stold() does not work with Qt in Linux
-
Hi!
I am trying to get a long double value from a string using the std::stold function but I can only get the integer part (including the dot). This issue only seems to exist when I use Qt in Linux (in Windows works fine) but if I run that part of the code without using any Qt class, I get the the variable with full precision as expected.
I know that Qt provides other methods to implement this but I would like to use standard C++ libraries in this part of the code since it may be necessary to build it without Qt.
Any thoughts?
Regards!
-
Qt is changing the locale. You have to set it back to "C" when you want to parse floating point numbers.
/edit: you must be aware that everyone can change the locale so before you pass stuff you should make sure that the locale is correct no matter if you use Qt or not.
-
Thank you! It solved the problem.