convert double to string

D

Denis

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.00000000000000000000023 should be string
0.00000000000000000000023 and not 0.00 or 2.3-E24

I tried it with
Console.WriteLine(dd.ToString("X", CultureInfo.InvariantCulture))
X=different numbertypes like G,D,N,...

Double.Parse(dd, NumberStyles.AllowCurrencySymbol Or
NumberStyles.Number Or ...

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

Is there anyone out there who allready found a solution for it?
 
J

Jon Skeet [C# MVP]

Denis said:
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
http://pobox.com/~skeet/csharp/floatingpoint.html

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

0.000000000000000000000229999999999999980614404973731825433997863397240
965158599261021488135980916922562755644321441650390625
 
D

Denis

If you need the absolute *exact* value, you can use the DoubleConverter
which can be found onhttp://pobox.com/~skeet/csharp/floatingpoint.html

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

0.000000000000000000000229999999999999980614404973731825433997863397240
965158599261021488135980916922562755644321441650390625

Thanks, helped very much
 

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