16,748
社区成员
发帖
与我相关
我的任务
分享
const
RightNum = 99;
procedure TForm1.btn2Click(Sender: TObject);
var
i, j, nSum, nCount: Integer;
fSum: Double;
GroupList: array [0..99] of TStringList; //报价分区间
AvgList: array [0..99] of Double; //每个区间的报价平均值
begin
//分组
for i := Low(GroupList) to High(GroupList) do
GroupList[i] := TStringList.Create;
for i := 0 to data.ADOQuery_jl.RecordCount - 1 do
begin
j := Trunc(Abs((StrToInt(NumList[i]) / RightNum) * 100 - 100)) - 1;
GroupList[j].Add(data.ADOQuery_jl.FieldByName('tbbj').AsString);
end;
//计算
for i := Low(GroupList) to High(GroupList) do
begin
AvgList[i] := 0;
if GroupList[i].Count > 0 then
begin
nSum := 0;
for j := 0 to GroupList[i].Count - 1 do
nSum := nSum + StrToInt(GroupList[i][j]);
AvgList[i] := nSum / GroupList[i].Count;
end;
end;
fSum := 0;
nCount := 0;
for i := Low(AvgList) to High(AvgList) do
if AvgList[i] > 0 then
begin
nCount := nCount + 1;
fSum := fSum + AvgList[i];
end;
ShowMessage(FloatToStr(fSum / nCount));
mmo2.Lines.Clear;
for i := Low(GroupList) to High(GroupList) do
if GroupList[i].Count > 0 then
mmo2.Lines.Add(GroupList[i].CommaText)
else
mmo2.Lines.Add('...');
end;