GithubHelp home page GithubHelp logo

Comments (8)

texus avatar texus commented on May 31, 2024

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.

klusekrules avatar klusekrules commented on May 31, 2024

No problem, I will do it.

from tgui.

texus avatar texus commented on May 31, 2024

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.

klusekrules avatar klusekrules commented on May 31, 2024

I'll do it today later. Over the next two and a half hours I do not have access to the computer.

from tgui.

klusekrules avatar klusekrules commented on May 31, 2024

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.

texus avatar texus commented on May 31, 2024

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.

klusekrules avatar klusekrules commented on May 31, 2024

Here is output:

2
2
2
2.3
2
2
2.3
2

from tgui.

texus avatar texus commented on May 31, 2024

Thanks for testing, your problem should be fixed in the latest version.

from tgui.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.