Comments (8)
I didn't know it would be saved in a different way depending on the locale. I thought it would always use a dot, since this is what you have to use inside c++ anyway.
I'll look into this issue, I just hope that it doesn't also start saving larger number like "10,000.00" in some locales, because then it would get even worse to parse. But I'm actually going to see if I can always just save the one with the dot instead of depending on the locale, that would be easier.
I may ask you to test some code snippet later to tell me what it does because I may not be able to test this myself.
from tgui.
No problem, I will do it.
from tgui.
Could you show the output of the following program?
#include <iostream>
#include <string>
#include <sstream>
template <typename T>
std::string to_string_1(T value)
{
std::ostringstream oss;
oss << value;
return oss.str();
}
template <typename T>
std::string to_string_2(T value)
{
std::ostringstream oss;
oss.imbue(std::locale::classic());
oss << value;
return oss.str();
}
int main()
{
float f = 1.5f;
std::cout << f << std::endl;
std::cout << std::to_string(f) << std::endl;
std::cout << to_string_1(f) << std::endl;
std::cout << to_string_2(f) << std::endl;
std::cout << std::stof("2.5") << std::endl;
std::cout << std::stof("2,5") << std::endl;
}
from tgui.
I'll do it today later. Over the next two and a half hours I do not have access to the computer.
from tgui.
The output of the above program:
1.5
1.500000
1.5
1.5
2.5
2
but when I added at the beginning of the main something like this:
...
int main()
{
std::locale pl("Polish");
std::locale::global(pl);
float f = 1.5f;
...
The output is following:
1.5
1,500000
1,5
1.5
2
2.5
from tgui.
The to_string worked like I expected but I hoped that the 5th number would stay 2.5 after changing the locale. So could you show the result of the following code as well? The 7th number should be 2.3 if all goes well.
#include <iostream>
#include <string>
#include <sstream>
int stoi(const std::string& value)
{
int result;
std::istringstream iss(value);
iss >> result;
return result;
}
float stof(const std::string& value)
{
float result;
std::istringstream iss(value);
iss >> result;
return result;
}
int stoi_l(const std::string& value)
{
int result;
std::istringstream iss(value);
iss.imbue(std::locale::classic());
iss >> result;
return result;
}
float stof_l(const std::string& value)
{
float result;
std::istringstream iss(value);
iss.imbue(std::locale::classic());
iss >> result;
return result;
}
int main()
{
std::locale pl("Polish");
std::locale::global(pl);
std::cout << stoi("2.3") << std::endl;
std::cout << stoi("2,3") << std::endl;
std::cout << stof("2.3") << std::endl;
std::cout << stof("2,3") << std::endl;
std::cout << stoi_l("2.3") << std::endl;
std::cout << stoi_l("2,3") << std::endl;
std::cout << stof_l("2.3") << std::endl;
std::cout << stof_l("2,3") << std::endl;
}
from tgui.
Here is output:
2
2
2
2.3
2
2
2.3
2
from tgui.
Thanks for testing, your problem should be fixed in the latest version.
from tgui.
Related Issues (20)
- Autocomplete support for EditBox HOT 2
- Can not input CJK words HOT 9
- Black background shown when changing window size HOT 4
- How to customize the window's title bar and frame HOT 2
- How to implement a polygon window HOT 2
- Hover style does not disappear when mouse moves out of the window HOT 6
- Add a 2d chart or rendering 3d data for TGUI? HOT 1
- Chinese support? HOT 5
- Focus Issues HOT 1
- [ANNOUNCE] The TGUI now distributed via MSYS2 on Windows HOT 1
- CMake fails to install pkg-config files HOT 2
- On macOS, Input Method Editors(IME) behavior seems incorrect. HOT 6
- How to use SDL2/3 backend with cmake `FetchContent` HOT 2
- [Question] How to compile my first example of TGUI ? HOT 13
- [Bug] Dead radio button text HOT 3
- [Bug] Tabs state after disabled tab click HOT 2
- FileDialog documentation needs clarification and maybe working examples HOT 4
- Is there a C binding? HOT 12
- Raylib backend? HOT 15
- Cannot delete widgets inside of the gui-builder HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tgui.