So any entry on my Database has (ID, tag, value, timestamp, status).
I´ll load one entry into 'profilData' and then only concentrate on the "value" row.
DataTable profilData = skzAdapterText.LoadValuesText(time);
String SQLvalues = (String)profilData.Rows[0][2];
The String I get looks similar to this:
NaN#Nan#44.20216139610997#45.35340149990988#45.44329482112824#45.1593428796393#NaN#NaN
I then split that String at each '#' and store the results in an Array.
String[] values;
values = SQLvalues.Split('#');
My aim is to be able to sum those values up. I am currently trying to Parse or Convert the String into a Double but whenever I do so the Double looks like this:
4420216139610997
The point/comma just gets removed.
Since I am in my first year of Education I don´t have much experience on all of this. Any help is appreciated.
Full Code:
String[] values;
List<Double> valueList = new List<Double>();
int profilePosCount = 5;
for (int i = 0; i < profilePosCount; i++)
{
int n = 0;
DataTable profilData = skzAdapterText.LoadValuesText(time);
String SQLvalues = (String)profilData.Rows[0][2];
n++;
values = SQLvalues.Split('#');
double summe = 0;
int counter = 0;
foreach (String tmpRow in values)
{
try
{
Double value = Convert.ToDouble(tmpRow); //Double.Parse(tmpRow);
counter++;
if (!tmpRow.ToString().Equals("NaN"))
{
if (!value.ToString().Equals("0"))
{
summe = summe + value;
}
}
}
catch (Exception ex)
{
}
}
if (summe != 0 && counter != 0)
valueList.Add(summe / counter);
}
doubleelements stored asdouble. So you can skip the step of casting to string and get doubles directly. An empty catch is another bad idea.Double.Parse(tmpRow, CultureInfo.InvariantCulture)