Delphi 中怎么实现一个公式求整数去掉小数点后面部分,和怎么让程序关闭后在打开edit显示关闭前的数据。

procedure TForm1.Button1Click(Sender: TObject);
begin
a:=strtofloat(edit1.text);
b:=strtofloat(edit2.text);
c:=strtofloat(edit3.text);
d:=strtofloat(edit4.text);
g:=strtofloat(edit7.text);
h:=strtofloat(edit8.text);
i:=strtofloat(edit9.text);
j:=strtofloat(edit10.text);
k:=strtofloat(edit11.text);
l:=strtofloat(edit12.text);
edit6.Text:=FloatToStr((g-1)*(9*(1+0.02*a)*c)/((9*(1+0.02*a)*c)+(1+0.02*b)*d));
edit5.text:=FloatToStr(g-1-((g-1)*(9*(1+0.02*a)*c)/((9*(1+0.02*a)*c)+(1+0.02*b)*d)));
edit11.Text:=FloatToStr((g-1)*(9*(1+0.02*a)*h)/((9*(1+0.02*a)*h)+(1+0.02*b)*i));
edit10.text:=FloatToStr(g-1-((g-1)*(9*(1+0.02*a)*h)/((9*(1+0.02*a)*h)+(1+0.02*b)*i)));
edit13.text:=floattostr(strtofloat(edit5.Text)+strtofloat(edit10.Text ));
edit14.text:=floattostr(strtofloat(edit6.Text)+strtofloat(edit11.Text ));
end;
现在edit5、6、10、11是有小数的。用什么办法能得到整数

1、关于取整,你没说取整规则。
添加引用:Math
直接删除小数部分,返回整数:trunc,如果trunc(2.234),则返回 2。其他:
trunc 和 round 是 system unit 里的函数,缺省就可以用。
floor 直接往小的取,比如 floor(-123.55)=-124,floor(123.55)=123
trunc 直接切下整数,比如 trunc(-123.55)=-123, floor(123.55)=123
ceil 直接往大的取,比如 ceil(-123.55)=-123, ceil(123.55)=124
round 计算四舍五入,比如 round(-123.55)=-124,round(123.55)=124

2、重启后text自动读取
两种方案,写注册表,或者写ini文件。
写注册表:不用额外添加文件,速度快,但会使注册表变大。不过数据少也无所谓了。
写ini文件:需要生成额外的文件。引用IniFiles。
procedure TForm1.Button2Click(Sender: TObject);
var
ini:TIniFile;
num : integer;
name: string;
begin
Ini := TIniFile.Create('c:\aa.ini');
//读取
num:= ini.ReadInteger('nums','num1',0);
name:= ini.ReadString('names','name1','');
//写入
name := '李三';
num := 1;
ini.WriteString('names','name1',name);
ini.WriteInteger('nums','num1',num);
end;

在你的窗口退出时onclose事件,把每个text的内容写入ini文件
在你的窗口启动时onCreate事件或其他,读取,并给text赋值。
温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-03-27
1、关于取整,你没说取整规则。
添加引用:Math
直接删除小数部分,返回整数:trunc,如果trunc(2.234),则返回 2。其他:
trunc 和 round 是 system unit 里的函数,缺省就可以用。
floor 直接往小的取,比如 floor(-123.55)=-124,floor(123.55)=123
trunc 直接切下整数,比如 trunc(-123.55)=-123, floor(123.55)=123
ceil 直接往大的取,比如 ceil(-123.55)=-123, ceil(123.55)=124
round 计算四舍五入,比如 round(-123.55)=-124,round(123.55)=124

2、重启后text自动读取
两种方案,写注册表,或者写ini文件。
写注册表:不用额外添加文件,速度快,但会使注册表变大。不过数据少也无所谓了。
写ini文件:需要生成额外的文件。引用IniFiles。
procedure TForm1.Button2Click(Sender: TObject);
var
ini:TIniFile;
num : integer;
name: string;
begin
Ini := TIniFile.Create('c:\aa.ini');
//读取
num:= ini.ReadInteger('nums','num1',0);
name:= ini.ReadString('names','name1','');
//写入
name := '李三';
num := 1;
ini.WriteString('names','name1',name);
ini.WriteInteger('nums','num1',num);
end;

在你的窗口退出时onclose事件,把每个text的内容写入ini文件
在你的窗口启动时onCreate事件或其他,读取,并给text赋值。
第2个回答  2013-03-28
delphi的取整函数round、ceil和floor
round 四舍六入五留 round(11.5) = 12 round(12.5) = 12
floor 向下取整。 floor(11.234)=11 cell 向上取整 cell(11.123)=12

想关闭后再显示 那就得找个地方把值存起来。是我就会存到ini中。
第3个回答  2013-03-26
1. 求整数用Roundto()函数。
2. 保存数据,关闭前将数据存储在临时文本文件,一般用ini文件为好。追问

我是新手新手 Roundto()函数怎么运用。怎么输出到ini又怎么读取

追答

1. Roundto(), math单元里。
RoundTo(1234567, 3) 1234000
RoundTo(1.234, -2) 1.23
2.直接写到一个文本文件里吧
{字符串写到文件}
procedure StringToFile (nString:string;mFileName:TFileName );
var
tFile:TextFile;
begin
AssignFile(tFile,mFileName );
Rewrite(tFile );
Write(tFile,nString);
CloseFile(tFile );
end;

相似回答