(*
Common format specifiers
-----------------------------------
%-10s { Left-aligned string, width 10 }
%10s { Right-aligned string, width 10 }
%5d { Integer, width 5 }
%08d { Integer, width 8, padded with zeros }
%12.2f { Float, width 12, 2 decimal places }
*)
program FixedWidthFields;
{$mode objfpc}{$H+}
uses
SysUtils;
{ Formats a record using fixed-width fields }
function FormatRecord(const Name: string; Age: Integer;
Salary: Double): string;
begin
{
%-15s = left-aligned string, width 15
%10d = right-aligned integer, width 10
%12.2f = floating-point value, width 12, 2 decimal places
}
Result := Format('%-15s%10d%12.2f',
[Name, Age, Salary]);
end;
var
Output: string;
begin
{ Store the formatted string in a variable }
Output := FormatRecord('R2D2', 96, 185000.0);
WriteLn(Output);
end.
{
run:
R2D2 96 185000.00
}