2
Answers

Converting string to decimal

Photo of john kanyora

john kanyora

7y
1.8k
1
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
Photo of Nikhil Sangani
730 1.2k 290.7k 7y
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
Photo of john kanyora
NA 242 48.3k 7y
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]);