请大家指点,谢谢(20分)

  • 主题发起人 主题发起人 cfVictoria
  • 开始时间 开始时间
C

cfVictoria

Unregistered / Unconfirmed
GUEST, unregistred user!
已知两个实数a=1.2和b=3.4, 显示他们的 和 差 积 商。
源代码如下:
procedure TForm1.Button1click(Sender: Tobject);
const
a: real=1.2;
b: real=3.4;
var
s,D,M,V:AnsiString;
begin
Str(a+b:5:2,S);//将a+b结果取两位小数,总宽度5位转换为串
Str(a-b:5:2,D);
Str(a*b:6:3,M);
Str(a/b:6:3,V);
S :=‘和是:’+ S +。。。;//组织显示字符串
label1.caption := S;
end;
_----------------------------------------------------------
----------------------------------------------------------
我的问题是:
求他们a b 的和 差 积 商, 那在这里5:2 和6:3 是怎莫回事?
谢谢!
 
procedure Str(X [: Width [: Decimals ]]
var S);
5:2是5位宽度,小数2位。定义数据长度和小数位置而已。
 
是的,zywcd已经说的很清楚了:)
 
谢谢zywcd和Johnny_du,但我还是不明白,定义数据长度和小数位置是必须的过程吗?另外怎莫是5位宽度?
 
No,the length and the precision of the number X is not necessary, in other words, it's optional.

The procedure Str,formats a string and returns it to a variable.

procedure Str(X [: Width [: Decimals ]]
var S);

Description

Str converts X to a string representation according to the Width and Decimals formatting parameters. The effect is like a call to Write except the resulting string is stored in S instead of being written to a text file.

X is an integer-type or real-type expression. Width and Decimals are integer-type expressions. S is a string-type variable or a zero-based character array variable if extended syntax is enabled.

Here's an Example for this procedure:
function MakeItAString(I: Longint): string;

{ Convert any integer type to a string }
var
S: string[11];
begin
Str(I, S);
Result:= S;
end;

begin
Canvas.TextOut(10, 10, MakeItAString(-5322));
end;
So when you call this function in an application, it'll draw some Numbers in the window with the given formats.
 

Similar threads

D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
D
回复
0
查看
777
DelphiTeacher的专栏
D
后退
顶部