Scientific Notation when serializing doubles

G

Guest

Hi. We put data on MSMQ queues using the Message ctor as follows:

Message myMessage = new Message(myObject);

As I understand it, this will use an XmlSerializer to serialize the body of
the message when it is placed on the queue. We have noticed that if myObject
contains doubles with small values (e.g. 0.0000000001) the serilized object
will represent these values in scientific notation (e.g. 1E-10).

Is this standard behaviour of the XmlSerializer, and is there any workaround?

Thanks

kh
 
K

Kevin Yu [MSFT]

Hi kh,

As you know, this is the designed behavior for XmlSerializer. Long decimal
data will be serialized as scientific notation. This is designed to
decrease the size of the serialized data, since these data might be passed
through network.

As far as I know, we cannot change this behavior. Is there any particular
reason you don't need your data to be casted? Let's see if we can find some
workaround on this.

Kevin Yu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
G

Guest

Kevin

Thanks for your reply. The consumer of the messages uses an XSLT
transformation engine which cannot parse numbers in scientific notation
(although we are now investigating whether this engine can be modified).

I think XmlSerializer is hardcoded to call one of the Double.ToString()
methods on double values which will always result in scientific notation as
we have observed. As far as I can tell the only way around this is to
implement custom serialization, which is far from ideal.

kh
 
K

Kevin Yu [MSFT]

Hi kh,

The simplest way to resolve this issue, is to use decimal type instead of
the double type. The decimal values will not be casted to scientific
notation.

Kevin Yu
Microsoft Online Community Support
==================================================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
K

Kevin Yu [MSFT]

Hi kh,

I'd like to know if this issue has been resolved yet. Is there anything
that I can help. I'm still monitoring on it. If you have any questions,
please feel free to post them in the community.

Kevin Yu
Microsoft Online Community Support
==================================================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 

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

Similar Threads


Top