locked
Converting double to string in locale agnostic way in C++ RRS feed

  • Question

  • Hi,

    I want to convert a double to string in C++. I don't want to use the locale settings i.e. I always want to use '.' as decimal separator. All the functions like sprintf or _gcvt_s or c++ string buffer pick settings from locale.

    1. Is there any method to convert double to string without using locale settings.

    2. If 1. is not possible, How can I create my own locale to use in sprintf function. I don't want to use the system locales (like english, german etc.) since user can change them and I don't want to change them from my code.

    Any help will be appreciated.


    Rajiv Bansal
    Wednesday, September 14, 2011 7:42 AM

Answers

  • RajivBansal wrote:

    I want to convert a double to string in C++. I don't want to use the  locale settings i.e. I always want to use '.' as decimal
    separator. All the functions like sprintf or _gcvt_s or c++ string  buffer pick settings from locale.

    _create_locale, _sprintf_l


    Igor Tandetnik

    • Marked as answer by Rob Pan Monday, September 19, 2011 9:25 AM
    Wednesday, September 14, 2011 12:09 PM