views:

695

answers:

5
var i : integer;

i := 1234567;

Given the above, I want the string "1,234,567" as output (assuming UK locale). IntToStr just gives me "1234567". I'm sure there's a one-liner for this, but I can't find it...

+3  A: 

s := FormatFloat('#,##0', i);

Uwe Raabe
+7  A: 

Try the format function.

Label1.Caption := Format('%.0n', [i + 0.0]);
Bruce McGee
A: 

stringreplace(format('%n',[1234567.0]),'.00','',[]);

Mark
A: 

Format('%n', [12345.678]);

Osama ALASSIRY
+3  A: 

Or if you need to be threadsafe or want to ensure you use the system default locale or want to specify one:

function FormatIntFromLCID(const AValue: Integer; const LCID: Integer = LOCALE_SYSTEM_DEFAULT): string;
var
  AFormatSettings: TFormatSettings;
begin
  GetLocaleFormatSettings(LCID, AFormatSettings);
  Result := FormatFloat('#,##0',AValue, AFormatSettings);
end;

see this post for a more complete discussion about formatting/locales

François