2

请帮忙,我怎样才能将一个真正的声明变量转换为一个字符串。有没有像 IntToStr() 这样的函数?RealToStr() 函数不起作用。

4

4 回答 4

5

SysUtils单元中有一堆转换例程,即FloatToStrFloatTo*函数。另请参阅格式功能。

于 2012-02-07T08:52:25.770 回答
1

一个非常古老的方法使用“Str”过程,它有两个参数:第一个是实数或整数,第二个是字符串变量,格式化后的数字将被放入其中。

例子:

i:= 1;
str (i, a);   // a = '1'
r:= 1.5;
str (r:2, a); // a = '1.50'
于 2012-02-07T10:03:20.917 回答
0

这取决于您使用的 Delphi 版本。较新版本中有一个 FloatToStr。

于 2012-02-07T08:53:07.577 回答
0

I think something like this would work...

procedure TestConversion;
Var
    StringValue : String;
    RealValue : Real;
    begin
        RealValue := 1 + 1.95;
        Str(RealValue:0:2,StringValue);
        // to display it in a label for example, it should be like this:
        Label1.Caption :=  StringValue + ' is a Real Value!';
    end;

so the output should be displayed in the Label1.Caption(as example) without problems like this:

2.95 is a Real value!

于 2021-05-06T03:10:43.650 回答