![]() |
decimal symbol problem (using libxml2)
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); } |
Re: decimal symbol problem (using libxml2)
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=...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 |
Re: decimal symbol problem (using libxml2)
Flash Gordon <spam@flash-gordon.me.uk> 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) kst-u@mib.org <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. |
| All times are GMT. The time now is 01:52 AM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.