Converting string to decimal
Am having problem in my code when converting string to decimal..am getting the error "for (int i = 0; i
Am using the below code:
{
x[i] = dt.Rows[i][0].ToString();
y[i] = string.Format("{0:c}",Convert.ToInt32(dt.Rows[i][1]);
}
Answers (2)
1
Hi John,
Please use like this.
You can only store string value in string array.
DataTable dt = new DataTable();
string[] x = new string[100];
string[] y = new string[100];
for (int i = 0; i < dt.Rows.Count; i++)
{
x[i] = dt.Rows[i][0].ToString();
y[i] = Convert.ToDecimal(dt.Rows[i][1]).ToString();
}
Accepted 0
Nikhil am getting the error Cannot implicitly convert type 'string[]' to 'decimal[]' at this line of code which i have highlighted.
y[i] = Convert.ToDecimal(dt.Rows[i][1]);