Re: English-> German and GetNumberFormat()

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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
****

Norbert
Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.



Relevant Pages

  • Re: English-> German and GetNumberFormat()
    ... German uses the same windows character set and code page as the US version, ... 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. ... that locale is not automatically set to the current user's locale. ...
    (microsoft.public.vc.mfc)
  • Re: English-> German and GetNumberFormat()
    ... I am German, so maybe I can help here a little bit. ... same windows character set and code page as the US version, ... Even Excel does use the "nice" format for displaying the numbers in the ... that locale is not automatically set to the current ...
    (microsoft.public.vc.mfc)
  • Re: Your chance to buy a PSB television network and associated digital stations
    ... different from our European neighbours. ... It is one of the world's leading producers of television content ... a German version of Celador format Who Wants ...
    (uk.tech.digital-tv)
  • Re: Multilingual features in Excel
    ... To enable the dates to behave as German dates should you need to use the OS ... Click System Preferences ... You can use the Format tab to pick German for the region which will give ... other languages, you or your system administrator can customize Office ...
    (microsoft.public.mac.office.excel)
  • Re: tr(1) buggy with de_DE.ISO8859-1(5) locale?
    ... Determine the locale for the behavior of range ... Ranges are not broken, they just work as defined by the ... One thing I like about FreeBSD is that I have my German ... The only problem is that script authors that use tr ...
    (freebsd-stable)