decimal symbol problem (using libxml2)

Discussion in 'C Programming' started by corley, Jul 5, 2006.

  1. corley

    corley Guest

    Hello world,

    I am having a problem with the decimal symbol. The result of writing a
    floating-point-number

    to an xml document (using libxml2 from xmlsoft.org) is
    <number>10,1234</number>

    The result I want is a dot as decimal symbol, like this
    <number>10.1234</number>

    If I adjust the county settings of my computer and say the decimal
    symbol must be an dot it

    works out fine, but this is not a very good solution because I dont
    want to be dependent of

    the system settings of a computer.

    I have tried to use the setlocale function with setlocale(LC_ALL,
    "English"). This didnt

    seem to work.

    Anybody has an clue?

    Cheerz, David

    -----------------------------
    xmlTextWriterPtr writer = NULL;
    xmlDocPtr doc = NULL;
    char xmlFilename[100] = "uitvoer.xml";

    writer = xmlNewTextWriterDoc(&doc, 0);
    if (NULL != writer)
    {
    xmlTextWriterStartDocument(writer, NULL, "ISO-8859-1", NULL);
    xmlTextWriterStartElement(writer, BAD_CAST "Main");
    xmlTextWriterWriteFormatElement(writer, BAD_CAST "getal", "%f",
    10.12345);
    xmlTextWriterEndElement(writer);
    xmlFreeTextWriter(writer);
    xmlSaveFormatFile(xmlFilename, doc, 1);
    xmlFreeDoc(doc);
    }
    corley, Jul 5, 2006
    #1
    1. Advertising

  2. corley

    Flash Gordon Guest

    corley wrote:
    > Hello world,
    >
    > I am having a problem with the decimal symbol. The result of writing a
    > floating-point-number
    >
    > to an xml document (using libxml2 from xmlsoft.org) is
    > <number>10,1234</number>
    >
    > The result I want is a dot as decimal symbol, like this
    > <number>10.1234</number>
    >
    > If I adjust the county settings of my computer and say the decimal
    > symbol must be an dot it
    >
    > works out fine, but this is not a very good solution because I dont
    > want to be dependent of
    >
    > the system settings of a computer.
    >
    > I have tried to use the setlocale function with setlocale(LC_ALL,
    > "English"). This didnt
    >
    > seem to work.
    >
    > Anybody has an clue?


    I don't think that "English" is a standard locate. "C", on the other
    hand, is, and may well do what you want since it is the standard locale.
    What other locales are available is dependant on your system so you
    would have to ask in a group dedicated to your implementation, possibly
    a Linux group. One of my linux boxes appears to have locales en_US and
    en_GB, for example, but they are not part of the C standard.

    > Cheerz, David
    >
    > -----------------------------
    > xmlTextWriterPtr writer = NULL;
    > xmlDocPtr doc = NULL;


    <snip>

    This looks like you are using the libxml2 library, which again is
    non-standard and so off topic here (I use it myself, but I and all my
    current customers will be set to either a British, USA or standard C
    locale so I've not seen this problem). However, libxml2 has its own
    mailing lists and it might be worth searching them.
    http://xmlsoft.org/search.php?query=locale&scope=any&submit=Search ...
    returns a lot of hits which would be worth investigating.
    --
    Flash Gordon, living in interesting times.
    Web site - http://home.flash-gordon.me.uk/
    comp.lang.c posting guidelines and intro:
    http://clc-wiki.net/wiki/Intro_to_clc
    Flash Gordon, Jul 5, 2006
    #2
    1. Advertising

  3. Flash Gordon <> writes:
    > corley wrote:
    >> Hello world,
    >> I am having a problem with the decimal symbol. The result of writing
    >> a
    >> floating-point-number
    >> to an xml document (using libxml2 from xmlsoft.org) is
    >> <number>10,1234</number>
    >> The result I want is a dot as decimal symbol, like this
    >> <number>10.1234</number>
    >> If I adjust the county settings of my computer and say the decimal
    >> symbol must be an dot it
    >> works out fine, but this is not a very good solution because I dont
    >> want to be dependent of
    >> the system settings of a computer.
    >> I have tried to use the setlocale function with setlocale(LC_ALL,
    >> "English"). This didnt
    >> seem to work.
    >> Anybody has an clue?

    >
    > I don't think that "English" is a standard locate. "C", on the other
    > hand, is, and may well do what you want since it is the standard
    > locale. What other locales are available is dependant on your system
    > so you would have to ask in a group dedicated to your implementation,
    > possibly a Linux group. One of my linux boxes appears to have locales
    > en_US and en_GB, for example, but they are not part of the C standard.


    But be careful about calling setlocale(LC_ALL, "C"). This (or the
    equivalent) is done at program startup. If your program is operating
    in a different locale, it must be because there was another call to
    setlocale() with different arguments, possibly setlocale(LC_ALL, ""),
    which "specifies the locale-specific native environment". If you set
    the locale to "C", you could change the behavior of other parts of the
    program that depend on a native or other locale.

    It's possible to save and restore the locale; setlocale() with a null
    pointer as its second argument returns a pointer to a string
    representing the current locale. You can query and save the current
    locale, do your stuff, then set it back.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
    Keith Thompson, Jul 5, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andrés Giraldo

    .NET changes automatically the decimal symbol???

    Andrés Giraldo, Jun 29, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    385
    Andrés Giraldo
    Jun 29, 2004
  2. baumann@pan
    Replies:
    1
    Views:
    742
    Richard Bos
    Apr 15, 2005
  3. Guest
    Replies:
    2
    Views:
    179
    Foo Man Chew
    Dec 29, 2003
  4. Song Ma
    Replies:
    2
    Views:
    229
    Charles Oliver Nutter
    Jul 20, 2008
  5. Replies:
    6
    Views:
    1,780
Loading...

Share This Page