Hi, i have a convert problem:

double v3;
             foreach (String cvt in sortList2.Keys)
             {
                 if (!(sortList8.ContainsKey(cvt)))
                 {
                     sortList2.TryGetValue(cvt, out v3);
                     sortList8.Add(cvt, v3);
                     String.Format("{0:0.00}", sortList8[cvt]);
                     sortList8[cvt] = (v3 * 100 / textBox2.Lines.Length);
                    
                   //  how to convert the result to 2 decimal?
                    
                 }
             }
    
             IDictionaryEnumerator enumerator2 = sortList8.GetEnumerator();
            
             while (enumerator2.MoveNext())                
             {             
                 Comset.Items.Add("(" + enumerator2.Key.ToString() + ")" + "\t" + enumerator2.Value.ToString() + "\n");
                 ISUPP.Items.Add(enumerator2.Value.ToString()+"\n");                
             }

I believe doubles already have the ability to support decimals.

What do you mean by "to 2 decimal"? Do you have two values? What exactly do you want to convert from double to decimal?

What is 2 decimal?

Ya, i means 2 decimal places, sorry for made you all confused.

double v3;
             foreach (String cvt in sortList2.Keys)
             {
                 if (!(sortList8.ContainsKey(cvt)))
                 {
                     sortList2.TryGetValue(cvt, out v3);
                     sortList8.Add(cvt, v3);
                     String.Format("{0:0.00}", sortList8[cvt]);
                                        
                     sortList8[cvt] = (v3 * 100 / textBox2.Lines.Length);                                                         
                 }
             }

After executed, my codes seem like do nothing, it still had so many decimal places, was there any mistakes in my codes?

Problem had been solved, Thanks everyone:)

No. You can't limit a value to a specific number of decimal places, you can only output it with that kind of limit.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.