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);
}
}
By using a button: Select the cells that you want to format. On the Home tab, click Increase Decimal or Decrease Decimal to show more or fewer digits after the decimal point.
4.732 rounded to 2 decimal places would be 4.73 (because it is the nearest number to 2 decimal places). 4.737 rounded to 2 decimal places would be 4.74 (because it would be closer to 4.74).
By using round(_:) , ceil(_:) , and floor(_:) you can round Double and Float values to any number of decimal places in Swift.
My answer is pretty late but for those out there like me who want:
to convert to double/decimal and also want the value to always show 2 decimal places (.00) as String
tbtotal2.Text = Math.Round(total2, 2).ToString("#.00");
The below means two decimal places at all times.
"#.00"
The below means two decimal places if there is value.
"#.##"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With