convert double to string

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Denis

    convert double to string

    Hi,

    I am trying to convert a double to a string. The problem the value of
    the double may vary and I need to always the exact value without the
    exponential and without rounding.
    Example: double 0.0000000000000 0000000023 should be string
    0.0000000000000 0000000023 and not 0.00 or 2.3-E24

    I tried it with
    Console.WriteLi ne(dd.ToString( "X", CultureInfo.Inv ariantCulture))
    X=different numbertypes like G,D,N,...

    Double.Parse(dd , NumberStyles.Al lowCurrencySymb ol Or
    NumberStyles.Nu mber Or ...

    string.Format(" {0:0.####}", myNumber);

    Is there anyone out there who allready found a solution for it?
  • Jon Skeet [C# MVP]

    #2
    Re: convert double to string

    Denis <Denis.Nicklas@ googlemail.comw rote:
    I am trying to convert a double to a string. The problem the value of
    the double may vary and I need to always the exact value without the
    exponential and without rounding.
    If you need the absolute *exact* value, you can use the DoubleConverter
    which can be found on
    Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.


    However, be careful - for your example, there's no exact double with
    the value 0.0000000000000 0000000023. The closest is:

    0.0000000000000 000000002299999 999999999806144 049737318254339 97863397240
    965158599261021 488135980916922 562755644321441 650390625

    --
    Jon Skeet - <skeet@pobox.co m>
    http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
    World class .NET training in the UK: http://iterativetraining.co.uk

    Comment

    • Denis

      #3
      Re: convert double to string

      On 24 Apr., 20:52, Jon Skeet [C# MVP] <sk...@pobox.co mwrote:
      Denis <Denis.Nick...@ googlemail.comw rote:
      I am trying to convert a double to a string. The problem the value of
      the double may vary and I need to always the exact value without the
      exponential and without rounding.
      >
      If you need the absolute *exact* value, you can use the DoubleConverter
      which can be found onhttp://pobox.com/~skeet/csharp/floatingpoint.h tml
      >
      However, be careful - for your example, there's no exact double with
      the value 0.0000000000000 0000000023. The closest is:
      >
      0.0000000000000 000000002299999 999999999806144 049737318254339 97863397240
      965158599261021 488135980916922 562755644321441 650390625
      >
      --
      Jon Skeet - <sk...@pobox.co m>http://www.pobox.com/~skeetĀ  Blog:http://www.msmvps.com/jon.skeet
      World class .NET training in the UK:http://iterativetraining.co.uk
      Thanks, helped very much

      Comment

      Working...