Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / August 2007

Tip: Looking for answers? Try searching our database.

Serialization of Double gives a '1E-12' - I want 0.000000000001

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Nutshell - 29 Aug 2007 20:56 GMT
Hey

I am running into this issue.

I have a Serializable Class that has a Double member.

I am using XmlSerializer to serilaize this object,
If the Double member is large (or very small) , the XmlSerializer is
converting this to its Scientific Notation (ie. 0.000000000001 -> '1E-12')

I dont want '1E-12' but instead I want 0.000000000001

Any suggestions?

Thanks
Peter Duniho - 29 Aug 2007 21:06 GMT
> I have a Serializable Class that has a Double member.
>
[quoted text clipped - 3 lines]
>
> I dont want '1E-12' but instead I want 0.000000000001

I'm not clear on why the representation of the number is important.  The
two strings are equivalent.  But if it is, you should be able to
implement ISerializable for your class to override the default behavior.
 Then you can use whatever custom formatting you like to ensure that
the serialized data has the exact representation you want.

Pete
Nutshell - 29 Aug 2007 22:02 GMT
Thanks Peter -

The issue is that I do need the number representation.

And unfortunately , I have 100+ classes that I would need to implement an
ISerializable on -

you wouldnt happen to have a short example :)

> > I have a Serializable Class that has a Double member.
> >
[quoted text clipped - 11 lines]
>
> Pete
Peter Duniho - 30 Aug 2007 00:42 GMT
> The issue is that I do need the number representation.
>
> And unfortunately , I have 100+ classes that I would need to implement an
> ISerializable on -
>
> you wouldnt happen to have a short example :)

MSDN does a fine job of documenting ISerializable, so I don't think I
need to provide an example of that.  An example of dealing with a
hundred classes with one simple change, I don't think exists.  I'm sure
not aware of a way to do that.

Of course, you could implement your own version of Double that
serializes the way you want, and then use that instead of the built-in
Double everywhere.  You'd have to touch every class, but if you do it
right it should amount to little more than a global search-and-replace.

Another option: you could insert your own Stream in between the
serializing and the file output, looking for Doubles serialized as
scientific notation and expanding each one as you desire.  You serialize
to your own stream rather than the destination stream, and your stream
would write the modified results to the destination stream.

Me, I'd rather try to change the requirements than hack serialization
that way.  But that's not always possible, and I think you could
probably get what you wanted by doing that.

I'm assuming here that the serialized data is a text stream of some
sort, but since you're concerned about the string representation of the
serialized data, that seems like a safe assumption.

Pete

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.