Deserialization 1E-08 format

S

Serg

Hi. I have a problem with deserialization decimal value.
I have a simple class:

public class A
{
public decimal d;
}

The serialization a value 0.00000001 is OK. The file is

<?xml version="1.0" encoding="utf-8"?>
<A xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<d>1E-08</d>
</A>

If I try to do a deserialization I have an error. But if I
replace by hand
the value of the tag <d> to 0.00000001, I have no error.
How should I work with 1E-08 format?
 
T

Tian Min Huang

Hello,

Thanks for your post. I built a sample to check this issue, however, I am
not able to reproduce the problem. It serialize to 0.00000001 (enclosed by
<d> tag) instead of 1E-08. The following is my code, please check it on
your side:

//------------------------code snippet----------------
using System.Xml.Serialization;
using System.IO;

public class A
{
public decimal d;
}

public class Test
{
public static void Main(string[] args)
{
A a = new A();
a.d = 0.00000001m;
XmlSerializer serializer = new XmlSerializer(typeof(A));
TextWriter writer = new StreamWriter("MyDoc.xml");
serializer.Serialize(writer, a);
writer.Close();

TextReader reader = new StreamReader("MyDoc.xml");
A a1 = (A)serializer.Deserialize(reader);
reader.Close();
}
}
//-------------------------end of---------------------------

I look forward to your feedback.

Have a nice day!

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
S

Serg

Thank you for your answer. I tried to use your code, but
the result is the same: 1E-08 value. Only d = 0.0001m
serializes to <d>0.0001</d> (it's right), other values are:

0.00001m to 1E-05
0.000001m to 1E-06 etc.

I tried to use this code:

//------------------
CultureInfo ci = new CultureInfo("en-US");
System.Threading.Thread.CurrentThread.CurrentCulture = ci;
//------------------

but it doesn't help me.
 

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

Top