I have this textbox that accepts numbers, commas, and periods.
Let's say this textbox contains input 14,500.00
I tried to convert this number to decimal with Convert.ToDecimal(textbox.text)
but it's not working. Convert.ToDecimal()
to textboxes that contain input that has the format XXXX.DD
are converted to decimal but input with format X,XXX.DD
or any input with a thousand separator results to error:
Input string was not in correct format
Is Convert.ToDecimal()
appropriate in this case?
ADDITIONAL INFO:
Here is the form. If I click 'Add', the product of 'Price' and 'Quantity' should be displayed as 'Amount' in the datagridview.
The syntax in the 'Add' button includes:
DataRow dr;
dr = dsDetail.Tables["SalesOrderDetails"].NewRow();
dr["Amount"] = Convert.ToDecimal(txtSellingPrice.Text) * Convert.ToDecimal(txtQuantity.Text);
The Amount
field in my SalesOrderDetails
table has the datatype decimal(18,2)