Click here to Skip to main content
11,921,889 members (58,660 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# string

I have a double, and I want to change it to a string, like this:

double value;
string myString = value.toString();

When value is a number with less than 4 digits after the point, it works fine.
For example,
if value is 0, myString will be 0.
if value is 0.01, myString will be 0.01.

But in cases when value has 4 or more digits after the point, myString is created with a floating point (for example, 1E-05).

I want myString to be created in a format of 0.0000000X for any number of digits after the point, and never use the 1E-0X method.
I also want to keep myString as short as possible, for exmaple when the value is 0, i want myString to be 0 (and not 0.000000).

How can I do it?
Posted 11-Dec-12 21:04pm
What are you talking about? "value.toString()" cannot even compile...
user_code 12-Dec-12 2:22am
Of course it can, and it compiles..
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

double value;
decimal d= Convert.ToDecimal(value);
string myString = d.toString();
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

Go through the following MSDN link. All the required formats are explained.[^]
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

double d = 8.7888888888888888;
            float f = float.Parse(d.ToString());
            string str = f.ToString();
            richTextBox1.Text = str.Split('.')[0].ToString();

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 568
1 Dave Kreskowiak 285
2 Sergey Alexandrovich Kryukov 173
3 Richard MacCutchan 155
4 ppolymorphe 135
0 OriginalGriff 7,036
1 KrunalRohit 4,530
2 Sergey Alexandrovich Kryukov 3,286
3 George Jonsson 2,840
4 Suvendu Shekhar Giri 2,216

Advertise | Privacy | Mobile
Web04 | 2.8.151120.1 | Last Updated 12 Dec 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100