Hi all,
I am trying to get the maximum value, minimum value and average in the values in a string and separated by ; but it gives an error.
I am waiting for help.
Example code ;
Error :
---------------------------
'1.5' is not a valid floating point value.
---------------------------
Memo text :
1,5;2,1;1,6;
1,1;1,3;1;
1,9;0,1;0,5;
var
Data: array of Double;
MinValue, MaxValue, Sum: Double;
Average: Double;
var i : integer;
s : string;
strArray : TArray<string>;
charArray : Array[0..0] of Char;
begin
s := Memo1.Text;
charArray[0] := ';';
strArray := s.Split(charArray);
i := 0;
for i := 0 to Length(strArray) do
begin
Data[i] := StrToFloat(strArray[i]);
end;
var
Count: Integer;
i: Integer;
begin
MinValue := Data[0];
MaxValue := Data[0];
Sum := 0;
Count := Length(Data);
for i := 0 to Count - 1 do
begin
if Data[i] < MinValue then
MinValue := Data[i];
if Data[i] > MaxValue then
MaxValue := Data[i];
Sum := Sum + Data[i];
end;
Average := Sum / Count;
Edit1.Text := FloatToStr(MinValue);
Edit2.Text := FloatToStr(MaxValue);
Edit3.Text := FloatToStr(Average);
Edit4.Text := FloatToStr(Sum);