(99999.99米)怎么样Format成(99公里999米99厘米)?(41分)

  • 主题发起人 孔明.net
  • 开始时间

孔明.net

Unregistered / Unconfirmed
GUEST, unregistred user!
(99999.99米)怎么样Format成(99公里999米99厘米)?
 
好象format没有这种功能。
只能自己截串来实现。
 
自已写个函数很容易就解决了:
function Change(fMI: do
uble): String;
var
iKM, iMI, iCM: integer;
begin
iKM := Trunc(fMI / 1000);
iMI := Trunc(fMI - Trunc(fMI / 1000) * 1000);
iCM := Trunc((fMI - iKM * 1000 - iMI) * 100);
Result := Format('%d公里%d米%d厘米', [iKM, iMI, iCM]);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
Showmessage(Change(StrToFloat(Trim(Edit1.Text))));
end;
你可以对上面的程序进行优化,比如当fMI较小时可能会显示0公里或0米,
你可以做个判断来显示不同的格式!
 
接受答案了.
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
486
import
I
D
回复
0
查看
1K
DelphiTeacher的专栏
D
顶部