xmlserializer - serialize float cultureinfo

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

hello everyone,
I'm using the XmlSerializer to generate Xml-Files of my classes.
I do have some float's and double's that also should get serialized.

At the moment, XmlSerializer generates something like the following for
float numbers:
<myVal>4000.5</myVal>

But i need to get this in german culture... there shoud be a comma instead
of the point, so it should look like:
<myVal>4000,5</myVal>

It's REALLY important, that I can serialize it like that, because the
Xml-file is sent to a interface that only accepts the second number format.

I already tried to add the following before serialization, but it didn't work.

System.Threading.Thread.CurrentThread.CurrentCulture = new
System.Globalization.CultureInfo("de-AT");
System.Threading.Thread.CurrentThread.CurrentUICulture =
System.Threading.Thread.CurrentThread.CurrentCulture;

I don't have to get the best solution, ANY solution would help..

Thanks in advance,
Christian
 
a solution is to implement IXmlSerializable for the class which contains the
float

and WriteXml :

public void WriteXml(XmlWriter writer)
{
CultureInfo culture = new CultureInfo("at-DE");
NumberFormatInfo formatInfo = culture.NumberFormat;
writer.WriteElementString("myVal", System.Convert.ToString(myVal,
formatInfo));
}


Didier
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top