-1

For example, I have a number 0,000000005 and it's displayed in ListBox like 5E-09. So, I would like it to be displayed exactly 0,000000005. Is there any way to do that? Thanx a lot.

listView1.Items[i].SubItems.Add(Convert.ToString(0.000000005));
Denis Lolik
  • 299
  • 1
  • 4
  • 11
  • 1
    **Moderator Note:** No prior effort is required for this particular question. It's clear and reasonably scoped; if you know how to do it, then provide an answer. – Robert Harvey Aug 07 '14 at 15:58
  • 1
    **Note to OP:** You're looking for *Numeric Format Strings.* You can find them in the documentation here: http://msdn.microsoft.com/en-us/library/dwhawy9k(v=vs.110).aspx – Robert Harvey Aug 07 '14 at 16:00
  • Ok, thank you. And I'm sorry for my inattention to existing posts. – Denis Lolik Aug 07 '14 at 16:05

1 Answers1

2

Use a format specifier, like in your case:

listView1.Items[i].SubItems.Add(String.Format("{0:F9}", 0.0000005));

Generic examples:

double v = 17688.65849;
double v2 = 0.15;
int x = 21;

Console.WriteLine("{0:F2}", v); // 17688.66
Console.WriteLine("{0:N5}", v); // 17, 688.65849
Console.WriteLine("{0:e}", v);  // 1.768866e+004
Console.WriteLine("{0:r}", v);  // 17688.65849
Console.WriteLine("{0:p}", v2); // 15.00 %
Console.WriteLine("{0:X}", x);  // 15
Console.WriteLine("{0:D12}", x);  // 000000000021
Console.WriteLine("{0:C}", 189.99); // $189.99
Michel Keijzers
  • 15,025
  • 28
  • 93
  • 119
  • What if you don't know it is 9 digits? If it is not known in prior? – Sriram Sakthivel Aug 07 '14 at 16:05
  • @SriramSakthivel It will automaticall pad 0's. So 0.5 will become 0.500000000. Also it will automatically round if needed. – Michel Keijzers Aug 07 '14 at 16:06
  • If it is greater `0.00000000000000000005`? and I don't know its length? What format I can use.? As of now I'm using "0.################" like that a long custom format? Is there a better way? – Sriram Sakthivel Aug 07 '14 at 16:08
  • @SriramSakthivel 0.00000000000000000005 is smaller but it does not change. In this case you will see the rounded value: 0.000000000. If you want more digits you have to change the value, but in that case I would advice using the scientific format {0:e}. – Michel Keijzers Aug 07 '14 at 16:11