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# / April 2008

Tip: Looking for answers? Try searching our database.

convert double to string

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Denis - 24 Apr 2008 15:45 GMT
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?
Jon Skeet [C# MVP] - 24 Apr 2008 19:52 GMT
> 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

Signature

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

Denis - 28 Apr 2008 10:26 GMT
> > 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
[quoted text clipped - 12 lines]
> Jon Skeet - <sk...@pobox.com>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

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.