converting to double to two decimal places

c#, decimal, rounding

Solution

Use `Math.Round`

Math.Round(mydoublevalue, 2);

In your code

tbtotal2.Text = Math.Round(total2, 2).ToString(); 

Problem

Hi i am a c# novice would someone politely tell me how to convert the values of this piece of code to a double/rounded decimal.. thanks in advance ``` DataTable dtValues = new DataTable("GetValues"); strValueNumber = ValueNumber[0].ToString(); dtGetValues = SQLMethods.GetValues(strValueNumber); total = 0; for (int i = 0; i < dtValues.Rows.Count; i++) { total1 = total1 + Convert.ToInt32(dtGetValues.Rows[i]["total_1"]); total2 = total2 + Convert.ToDouble(dtGetValues.Rows[i]["total_2l"]) * .45; tbtotal1.Text = total1.ToString(); tbtotal2.Text = total2.ToString(); } } catch (Exception ex) { MessageBox.Show("Error in returning selected Values. " + "Processed with error:" + ex.Message); } } ```

Original source