Delphi 华氏度和摄氏度转换(亲测可用)

uses引用单元:math

华氏度转摄氏度: FloatToStr(Roundto(5/9*(华氏度(浮点型)-32),-2))\

摄氏度转华氏度:FloatToStr(RoundTo(摄氏度(浮点型)*9/5+32,-2))

例子:

华氏度转摄氏度:

procedure TForm1.btn3Click(Sender: TObject);
begin
  if trim(edt4.Text) <> '' then
    edt3.Text :=  FloatToStr(Roundto(5/9*(StrToFloat(Edt4.Text)-32),-2));
end;

摄氏度转华氏度:

procedure TForm1.btn4Click(Sender: TObject);
begin
if trim(edt6.Text) <> '' then
 edt5.Text := FloatToStr(RoundTo(StrToFloat(Edt6.Text)*9/5+32,-2));
end;

你可能感兴趣的:(Delphi,Delphi,华氏度,摄氏度)