Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > decimal symbol problem (using libxml2)

Reply
Thread Tools

decimal symbol problem (using libxml2)

 
 
corley
Guest
Posts: n/a
 
      07-05-2006
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);
}

 
Reply With Quote
 
 
 
 
Flash Gordon
Guest
Posts: n/a
 
      07-05-2006
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
 
Reply With Quote
 
 
 
 
Keith Thompson
Guest
Posts: n/a
 
      07-05-2006
Flash Gordon <(E-Mail Removed)> 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.velocityreviews.com/forums/(E-Mail Removed) <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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
decimal.Decimal formatting python@lists.fastmail.net Python 0 07-19-2010 12:32 PM
how to convert from Decimal('1.23456789') to Decimal('1.234') valpa Python 11 03-24-2009 07:11 AM
Error: Cannot convert Decimal("0.0000") to Decimal Vitaliy Python 1 05-29-2008 10:36 AM
TypeError: unsupported operand type(s) for -: 'Decimal' and 'Decimal'. Why? Gilbert Fine Python 8 08-01-2007 01:58 AM
Decimal to Packed Decimal Conversion in C++ Ven C++ 3 08-01-2006 03:56 PM



Advertisments