var
a,b,c,d1,d2:integer;
begin
a:=StrToInt(statusbar1.Panels [1].Text );
b:=StrToInt(statusbar1.Panels [3].Text );
c:=strtoInt(statusbar1.Panels [7].Text );
d1:=round((a-b)/a*100);
d2:=round((a-c)/a*100);
statusbar1.Panels [5].Text :=inttostr(d1)+'%';
statusbar1.Panels [9].Text :=inttostr(d2)+'%';
这样算出的d1,d2的值是整数,那么要保留小数怎么写?
a,b,c,d1,d2:integer;
begin
a:=StrToInt(statusbar1.Panels [1].Text );
b:=StrToInt(statusbar1.Panels [3].Text );
c:=strtoInt(statusbar1.Panels [7].Text );
d1:=round((a-b)/a*100);
d2:=round((a-c)/a*100);
statusbar1.Panels [5].Text :=inttostr(d1)+'%';
statusbar1.Panels [9].Text :=inttostr(d2)+'%';
这样算出的d1,d2的值是整数,那么要保留小数怎么写?
例:
var
a : Double;
b : string; a:= 111.254788;
b := FormatFloat('0.00',a)
d2:=round((a-c)/a*100);
--------------------------
Round()函数是求四舍五入的,结果为整数
试试这样行不行:
lsStr1 := Format('%.2f', [(a-b)/a*100]); //结果为字符串类型
lsStr2 := Format('%.2f', [(a-c)/a*100]); //结果为字符串类型