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");                
             }

What do you mean by "to 2 decimal"? Do you have two values? What exactly do you want to convert from double to 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?

Edited 5 Years Ago by leo88: n/a

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

This question has already been answered. Start a new discussion instead.