Optimized verion of AddThousandSeparator



Hello,

I was looking for very good way to force thousand separators to Integer (or float) formatted string (in Finlad thousand separators are not normally used in OS level).

I came up with this (found it with google)

function emdAddThousandSeparator(const S: string; Chr: Char = ' '): string;
var
I: Integer;
begin
Result := S;
I := Length(S) - 2;
while I > 1 do
begin
Insert(Chr, Result, I);
I := I - 3;
end;
end;


Then I was thinking that it could be defined like this

function IntToStrT(const AValue: Integer; AThousandsSeparator: Char = ' '): string;
(and one for float(s) maybe)

Maybe this way it would be more efficient, to convert it directly to string with forced thousand separator.

Where I could find routine to modify, pure pascal would do, in which I could implement thousand separator adding. Or does someone have optimized code for this already (or good way to force separators with RTL/VCL, with out changing the Thousand Separator char in ?system.pas/sysutils? (where ever it is, can't remember)...

-TP-
.



Relevant Pages