i found a error
System.FormatException: 'Input string was not in a correct format.'
in my c# project. i want to convert my decimal value to round but if value is "7.99" it's output is 7 only which is at "b". i use this function but i failed.
void Calculation()
{
double a = Convert.ToDouble(lblTFPc.Text); **//Error appears here**
double b = Convert.ToDouble(lbl1.Text);
double c = Convert.ToDouble(lblTPc.Text);
double d = Convert.ToDouble(lblSchOn.Text);
try
{
a = (c / d);
b = Math.Floor(a +0.0);
}
catch (Exception ex)
{
MetroFramework.MetroMessageBox.Show(this, "Error" + ex, "Stop", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
i changed the way but still an error
void Calculation()
{
try
{
decimal a = Convert.ToDecimal(txtValue.Text);
decimal b = Convert.ToDecimal(lblCtn.Text);
decimal c = Convert.ToDecimal(lblPc.Text);
decimal d = Convert.ToDecimal(lblCtnInPc.Text);
decimal e = Convert.ToDecimal(txtQtyCtn.Text);
decimal f = Convert.ToDecimal(lblCtnSize.Text);
decimal g = Convert.ToDecimal(lblTotalPc.Text);
decimal h = Convert.ToDecimal(txtQtyPc.Text);
decimal i = Convert.ToDecimal(txtTotalFreePc.Text); **//error is here I change lbl into txtbox but error still**
decimal j = Convert.ToDecimal(lblSchemeOn.Text);
decimal k = Convert.ToDecimal(lbl1.Text);
a = (b + c);
d = (e * f);
g = (h + d);
i = (g / j);
k = Math.Floor(i);
}
catch (Exception ex)
{
MetroFramework.MetroMessageBox.Show(this, "Error" + ex, "Stop", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
with try error is like this:
ErrorSystem.FormatException: Input string was not in a correct format. at System.Number.StringToNumber(String Str, NumberStryles options, NumberBuffer number, NumberFormatInfo info, Boolean parseDecimal) at System.Number.ParseDecimal(String value, NumberStyles options, NUmberFormatInfo numfmt) atSystem.Convert.ToDecimal(String value) at MyProject.Forms.frmPurchaseItem.Calculation() in [Filepath]
lbl is Control abbreviation for label and for textbox is txt. Check if the labels in your text property have text and not number. Maybe you put the label instead of the text boxes. Convert.ToDouble() can not perform the conversion if there is text.