Mega Code Archive

 
Categories / Delphi / Algorithm Math
 

How to show numbers with thousand separators

Title: How to show numbers with thousand separators function AddThousandSeparator(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; procedure TForm1.Button1Click(Sender: TObject); begin Edit1.Text := AddThousandSeparator('400500210', ''''); // -- 400'500'210 end;