c++boostlocalizationinternationalizationboost-locale

How to specify a custom decimal separator for numbers in Boost.Locale?


I've read the Boost.Locale docs several times through, but still can't find the answer to this seemingly easy problem: I need to output using a specific locale (e.g. ru_RU), but with a customized decimal separator (e.g. dot instead of comma). Is this possible?

For dates, there's the "ftime" manipulator that allows to specify a custom datetime format string. But is there anything like that for numbers?

Thanks!


Solution

  • You can use the C++ <locale> library.

    std::string russian_number_string(int n) {
        std::stringstream ss;
        ss.imbue(std::locale("ru_RU"));
        ss << n;
        return ss.str();
    }