Re: English-> German and GetNumberFormat()
- From: Joseph M. Newcomer <newcomer@xxxxxxxxxxxx>
- Date: Tue, 12 Dec 2006 16:47:49 -0500
See below...
On Tue, 12 Dec 2006 22:31:07 +0100, Norbert Unterberg <nunterberg@xxxxxxxxxxxxxxxxx>
wrote:
****
I am German, so maybe I can help here a little bit.
Elan Magavi schrieb:
I have been working with this app which allows users to type in a fixed
point value.. liike "1.045982"
The files which are sent with the app as samples use a decimal, (English) as
the seperator. In Germany, it is a comma.
I have used the GetNumberFormat api which will return that value as
1,045982.
That value is sent to a swscanf() like so
swscanf(procStr,_T("%lf"),&dVal);
Some general information about these functions and the German locales:
* Code page and font settings have nothing to do with it. German uses the same
windows character set and code page as the US version, as far as I know. It
begins to get difficult if you move more to the east, there you get the eastern
europe character sets. However, all characters that are used for number
formatting are still the same (in the ASCII range).
* GetNumberFormat() formats a numbers for sending them to the screen or to the
printer to make it look nice. The output of GetNumberFormat can not be reliably
parsed by any of the input functions, as far as I know of. The reason is that I
don't know any input function that deals with the tousands separator or with a
minus sign behind the number (-1245.6 could be displayed as "1.245,6-",
depending on the language settings page in control panel.
Even Excel does use the "nice" format for displaying the numbers in the data
cells, but as soon as you edit a cell, you get the "simple" number format in the
edit field.
* So to send data to another application, you might better stick to the number
formatting as done by the C/C++ runtime library. All the C/C++ runtime library
functions obey the number format set by the current locale. HOWEVER, that locale
is not automatically set to the current user's locale. For compatibility
reasons, C programms are set to the "C" locale by default. If your application
is locale-aware, you need to tell the library with a call to the setlocale()
function.
AHA! That's what I was referring to, I just wasn't sure what was going on in the
libraries (see my earlier reply where I said that it wasn't what he was doing, but whether
or not the C libraries were seeing the right thing!)
****
****
To set the printf/scanf formating to use the user's locale, you need to set at
least the LC_NUMERIC locale:
_tsetlocale(LC_NUMERIC, _T(""));
A call to
_tsetlocale(LC_ALL, _T(""));
sets all locale info to the user's default language, that includes string
sorting, date/time formatting and character handling functions.
Note that you can explicitly set the German locale with something like
_tsetlocale(LC_NUMERIC, _T("deu"));
on any language version of Windows.
Changing the number formating with LC_NUMERIC to German only changes the "." to
",", so -1.2345 will be printed as "-1,2345".
* Now you need to decide what output format you want to use for your files. It
depends on what type of software will read the files.
- The German version of Excel respects the user's locale, so it will read
files with the German formatted numbers (1,23456).
- On the other hand, most simple programs "hacked together" do not call
setlocale(), so they need the American (international?) number format, i.e. in
config files.
- Well written programs that read numbers from the user or from a file ask the
user if the number format is German or English, or try to auto-detect the number
format.
You see, there is no easy answer (as always)
I hope I could help!
Norbert Unterberg
Helped me, too. I've not used the C library formatting for international apps in a while,
so I wasn't aware of this! Thanks.
joe
****
Joseph M. Newcomer [MVP]
Norbert
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.
- References:
- English-> German and GetNumberFormat()
- From: Elan Magavi
- Re: English-> German and GetNumberFormat()
- From: Norbert Unterberg
- English-> German and GetNumberFormat()
- Prev by Date: Re: text parser
- Next by Date: Re: How to properly thread a singleton class?
- Previous by thread: Re: English-> German and GetNumberFormat()
- Next by thread: Re: English-> German and GetNumberFormat()
- Index(es):
Relevant Pages
|
Loading