Re: English-> German and GetNumberFormat()
- From: Norbert Unterberg <nunterberg@xxxxxxxxxxxxxxxxx>
- Date: Tue, 12 Dec 2006 22:31:07 +0100
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.
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
Norbert
.
- Follow-Ups:
- Re: English-> German and GetNumberFormat()
- From: Elan Magavi
- Re: English-> German and GetNumberFormat()
- From: Elan Magavi
- Re: English-> German and GetNumberFormat()
- From: Mihai N.
- Re: English-> German and GetNumberFormat()
- From: Joseph M . Newcomer
- Re: English-> German and GetNumberFormat()
- References:
- English-> German and GetNumberFormat()
- From: Elan Magavi
- English-> German and GetNumberFormat()
- Prev by Date: Re: Printing RTF text using a hidden CRichEditCtrl
- Next by Date: Re: English-> German and GetNumberFormat()
- Previous by thread: Re: English-> German and GetNumberFormat()
- Next by thread: Re: English-> German and GetNumberFormat()
- Index(es):
Relevant Pages
|
Loading