Question

How can I add spaces between numbers with DisplayFormat.

Like this example:

50130301037855000150550010000000131000000132

I'm need this:

5013 0301 0378 5500 0150 5500 1000 0000 1310 0000 0132

Anyone have an idea? Thanks.

Was it helpful?

Solution 2

I found the answer using DisplayFormat

9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999;0; 

Thanks all.

OTHER TIPS

You can not format like that just using the DisplayFormat property, but you can rely on the OnGetText event to make this happen.

I'm assuming your field is of string type, for example:

function InsertBlankEach4Chars(S: string): string;
begin
  Result := '';
  while S <> '' do
  begin
    Result := Result + Copy(S, 1, 4) + ' ';
    Delete(S, 1, 4);
  end;
  Result := Trim(Result);
end;

procedure TMyForm.MyQueryFieldGetText(Sender: TField;
  var Text: string; DisplayText: Boolean);
begin
  if DisplayText then
    Text := InsertBlankEach4Chars(Sender.AsString)
  else
    Text := Sender.AsString;
end;

Disclaimer: This code was written in the browser and is not tested. If you're going to use this in a time-sensitive process, I warn you this function may be optimized for better performance.

if you wnt to use it for currency then use this .

procedure TForm1.Edit1Change(Sender: TObject);
var  a :Currency;
begin
ThousandSeparator :=' ';
if edit1.Text <>'' then  a:=strtofloat(edit1.Text) else a:=0;
edit2.Text :=FloatToStrF(a,ffNumber, 12, 2);
end;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top