Decimal format conversion from one locale to another locale(en_US) Topic is solved
-
- Knows some wx things
- Posts: 44
- Joined: Fri Jul 05, 2019 8:47 pm
Decimal format conversion from one locale to another locale(en_US)
I use wxLocale wxLANGUAGE_SERBIAN and have a decimal format like 1,23 I would like to convert it to decimal in format wxLANGUAGE_ENGLISH like 1.23 how?
-
- Moderator
- Posts: 19163
- Joined: Fri Apr 21, 2006 8:03 pm
- Location: $FCE2
Re: Decimal format conversion from one locale to another locale(en_US)
Code: Select all
wxLocale locale(wxLANGUAGE_SERBIAN);
double f = (double)22/7;
wxLogMessage("%.2f", f);
::wxSetlocale(LC_NUMERIC, "C");
wxLogMessage("%.2f", f);
Use the source, Luke!
-
- Part Of The Furniture
- Posts: 4204
- Joined: Sun Jan 03, 2010 5:45 pm
Re: Decimal format conversion from one locale to another locale(en_US)
Does changing the locale like this affect the current thread or all threads? After wxLocale instance goes out of scope, what locale is set then - the previous one?
Also, I think that if you use just "C" locale instead of a country-specific one, you can just use wxString::FromCDouble() and avoid changing the locale from Serbian altogether.
I use wxString::FromCDouble()/ToCDouble() all the time when I work with input/output requiring a decimal point when the application locale uses a decimal comma.
-
- Moderator
- Posts: 19163
- Joined: Fri Apr 21, 2006 8:03 pm
- Location: $FCE2
Re: Decimal format conversion from one locale to another locale(en_US)
At least under Windows, it affects the current thread only.Does changing the locale like this affect the current thread or all threads?
Yes, the old one is restored.After wxLocale instance goes out of scope, what locale is set then - the previous one?
Use the source, Luke!
-
- Part Of The Furniture
- Posts: 4204
- Joined: Sun Jan 03, 2010 5:45 pm
Re: Decimal format conversion from one locale to another locale(en_US)
Are you sure about that? I think wxWidgets use setlocale internally (in wxSetLocale) and MS documentation seems to suggest that setlocale by default affects all threads
https://docs.microsoft.com/en-us/cpp/pa ... ew=vs-2019
-
- Moderator
- Posts: 19163
- Joined: Fri Apr 21, 2006 8:03 pm
- Location: $FCE2
Re: Decimal format conversion from one locale to another locale(en_US)
You're right. I only looked into the code for wxLocale, which uses SetThreadLocale and forgot about the wxSetlocale.
Use the source, Luke!
-
- Knows some wx things
- Posts: 44
- Joined: Fri Jul 05, 2019 8:47 pm
Re: Decimal format conversion from one locale to another locale(en_US)
Thanks for the helpful info.
This is what I needed : wxString::FromCDouble()/ToCDouble()
This is what I needed : wxString::FromCDouble()/ToCDouble()