Rod*_*ddy 5 delphi text-formatting
var i : integer;
i := 1234567;
Run Code Online (Sandbox Code Playgroud)
鉴于上述情况,我希望字符串"1,234,567"作为输出(假设英国语言环境).IntToStr只给了我"1234567".我确定这是一个单行,但我找不到它......
Bru*_*Gee 18
尝试格式化功能.
Label1.Caption := Format('%.0n', [i + 0.0]);
Run Code Online (Sandbox Code Playgroud)
Fra*_*ois 11
或者,如果您需要线程安全或者想要确保使用系统默认语言环境或想要指定一个:
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;
Run Code Online (Sandbox Code Playgroud)
有关格式化/区域设置的更完整讨论,请参阅此帖子