Re: English-> German and GetNumberFormat()

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



Norbert

I wanted to make sure i thanked you for your response. Thanks. going
through it all now..

Elan.


"Norbert Unterberg" <nunterberg@xxxxxxxxxxxxxxxxx> wrote in message
news:OyBUZTjHHHA.3952@xxxxxxxxxxxxxxxxxxxxxxx

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


.



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. ... Even Excel does use the "nice" format for displaying the numbers in the data ... functions obey the number format set by the current locale. ... libraries (see my earlier reply where I said that it wasn't what he was doing, ...
    (microsoft.public.vc.mfc)
  • 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)
  • Re: does rubys strftime not attempt POSIX-compliance?
    ... it refers to the "POSIX locale concept" and the ruby compliance with it. ... MS> nothing in common with the libc strftime except the name;-) ... I started using this ISO date format next to my signature on forms back in the early eighties. ...
    (comp.lang.ruby)
  • Re: datediff() and isdate() not working with hungarian date format (VB6)
    ... When I set in the control panel Hungry and then change the short date format ... Then Datediffand and isdate() do not work with strings. ... Dim t1 As String ... Most of the VB run-time functions are aware of your locale. ...
    (microsoft.public.vb.bugs)