应用场景
有时候需要在一个数字中间添加千位分隔符,方便查看。
函数代码
function AddThousandSeparator(const S: string; const C: Char): string;
var
I: Integer; // loops through separator position
begin
Result := S;
I := Length(S) - 2;
while I > 1 do
begin
Insert(C, Result, I);
I := I - 3;
end;
end;
//老版本中
function AddDefThousandSeparator(const S: string): string;
begin
Result := AddThousandSeparator(S, ThousandSeparator);
end;
//新版本中
function AddDefThousandSeparatorXE(const S: string): string;
begin
Result := AddThousandSeparator(S, FormatSettings.ThousandSeparator);
end;