Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8147297
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:18:17+00:00 2026-06-06T14:18:17+00:00

I am serializing values to an XML document. When I serialize a double ,

  • 0

I am serializing values to an XML document. When I serialize a double, I want to make sure I am not losing any precision, and that culture will not interfere. Or any other “gotchas” that I haven’t thought of.

Similarly for DateTime, I use ToBinary() to get a value that’s very safe to serialize.

So, what is the best method to serialize / deserialize a double value in C#?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T14:18:18+00:00Added an answer on June 6, 2026 at 2:18 pm

    In order to parse back the exact value, you should use the G17 format specifier, as documented here:

    d.ToString("G17")
    

    or

    $"{d:G17}"
    

    Note that this can fail to roundtrip on versions below .NET Core 3.0.


    Original answer below; the "r" format specifier mentioned actually has a bug so the documentation was incorrect.


    The round-trip format specifier "r" guarantees that if you use double.Parse on the string, you will get back the exact same value:

    d.ToString("r")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to XML-Serialize a complex type (class), that has a property of type
I have some XML that I am trying serialize like so: string Value =
I have an XML document that I am deserializing (VB .NET 3.5 Framework), changing
I'm serializing an object to xml in c# and I would like to serialize
My $.ajax() is not serializing the button name and value. I have a very
I'm serializing data from my Django model into json and placing that info in
I am serializing objects to XML using System.Xml.Serialization and this requires me to have
I am serializing data into xml by converting Dictionary into List. The serialization is
I am receiving an XML via an HttpPost to my service, and I want
How would you go about serialising a Map using simple XML so that it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.