Delphi: format (,
, )
, , ,
, . , ,
:
procedure
TForm1.btnCalkClick(Sender: TObject);
begin
lbResult.Caption:=FloatToStr(123/456);
end; |
:

,
, ? ,
format.
procedure
TForm1.btnCalkClick(Sender: TObject);
begin
lbResult.Caption:=Format('
%.3n',[123/456]);
end; |
:

Delphi
Format,
'C' .
, - ( []).
, %
:
d = ( )
e =
f =
g =
m =
n = ()
p =
s =
u =
x =
:
procedure
TForm1.btnCalkClick(Sender: TObject);
var i:integer;
begin
i:=123;
lbResult.Caption:=Format('%d
%x ',[i,i]);
end; |
:

:
%[Index:][-][Width][.Precision]Type
, :. - - ,
2 ,
.
:
procedure
TForm1.btnCalkClick(Sender: TObject);
begin
lbResult.Caption:=Format('%.4f',[123.456]);
end; |
:

,
format.
TListBox ( Standart).
lbFormatDemo.
OnClick:
procedure
TfrmFormatDemo.btnStartClick(Sender: TObject);
var
text : string;
begin
//
1
lbFormatDemo.Items.Add(Format('%s', ['Hello']));
//
lbFormatDemo.Items.Add(Format('String = %s', ['Hello']));
//
lbFormatDemo.Items.Add(Format('Decimal = %d',
[-123]));
lbFormatDemo.Items.Add(Format('Exponent = %e',
[12345.678]));
lbFormatDemo.Items.Add(Format('Fixed = %f',
[12345.678]));
lbFormatDemo.Items.Add(Format('General = %g',
[12345.678]));
lbFormatDemo.Items.Add(Format('Number = %n',
[12345.678]));
lbFormatDemo.Items.Add(Format('Money = %m',
[12345.678]));
lbFormatDemo.Items.Add(Format('Pointer = %p', [addr(text)]));
lbFormatDemo.Items.Add(Format('String = %s', ['Hello']));
lbFormatDemo.Items.Add(Format('Unsigned decimal = %u',
[123]));
lbFormatDemo.Items.Add(Format('Hexadecimal = %x',
[140]));
end; |
, :

,
:
procedure
TfrmFormatDemo.btnStartClick(Sender: TObject);
begin
//
// ,
//
<>, ,
lbFormatDemo.Items.Add(Format('Padded decimal = <%7d>',
[1234]));
// '-' ,
lbFormatDemo.Items.Add(Format('Justified decimal =
<%-7d>', [1234]));
// 0
lbFormatDemo.Items.Add(Format('0 padded decimal =
<%.6d>', [1234]));
//
// ,
lbFormatDemo.Items.Add(Format('Width + precision =
<%8.6d>', [1234]));
//
//
lbFormatDemo.Items.Add(Format('Reposition after 3
strings = %s %s %s %1:s %s',['Zero',
'One', 'Two',
'Three']));
// , , *
//
ECONVERTERROR.
lbFormatDemo.Items.Add(Format('In line = <%10.4d>',
[1234]));
lbFormatDemo.Items.Add(Format('Part
data driven = <%*.4d>', [10, 1234]));
lbFormatDemo.Items.Add(Format('Data driven = <%*.*d>', [10, 4, 1234]));
end; |

|