Fórum Formatar Edit com unidades #458901
19/10/2013
0
usuário digita 1500000 por exemplo automaticamente o Edit.text adicione os '.' (pontos) nos locais certos, tipo, 1.500.000
Alguém pode me ajudar?
Desde já, muito obrigado!
Helton Ferreira
Curtir tópico
+ 0Post mais votado
19/10/2013
no evento onkeyup do edit coloque o código abaixo:
procedure TFormContrato.edValorTotalKeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
var s: String;
begin
if (Key in [96..107]) or (Key in [48..57]) then
begin
S := edValorTotal.Text;
S := StringReplace(S,',','',[rfReplaceAll]);
S := StringReplace(S,'.','',[rfReplaceAll]);
if Length(s) = 3 then
begin
s := Copy(s,1,1)+','+Copy(S,2,15);
edValorTotal.Text := S;
edValorTotal.SelStart := Length(S);
end
else
if (Length(s) > 3) and (Length(s) < 6) then
begin
s := Copy(s,1,length(s)-2)+','+Copy(S,length(s)-1,15);
edValorTotal.Text := s;
edValorTotal.SelStart := Length(S);
end
else
if (Length(s) >= 6) and (Length(s) < 9) then
begin
s := Copy(s,1,length(s)-5)+'.'+Copy(s,length(s)-4,3)+','+Copy(S,length(s)-1,15);
edValorTotal.Text := s;
edValorTotal.SelStart := Length(S);
end
else
if (Length(s) >= 9) and (Length(s) < 12) then
begin
s := Copy(s,1,length(s)-8)+'.'+Copy(s,length(s)-7,3)+'.'+
Copy(s,length(s)-4,3)+','+Copy(S,length(s)-1,15);
edValorTotal.Text := s;
edValorTotal.SelStart := Length(S);
end
else
if (Length(s) >= 12) and (Length(s) < 15) then
begin
s := Copy(s,1,length(s)-11)+'.'+Copy(s,length(s)-10,3)+'.'+
Copy(s,length(s)-7,3)+'.'+Copy(s,length(s)-4,3)+','+Copy(S,length(s)-1,15);
edValorTotal.Text := s;
edValorTotal.SelStart := Length(S);
end;
end;
end;Marcos Saffran
Gostei + 1
Mais Posts
19/10/2013
Marcio
var
valor: double;
begin
valor := StrToCurr(Edit1.Text);
Edit1.Text := FormatFloat('#,.##', valor)
Gostei + 0
19/10/2013
Helton Ferreira
Acredito que não seja exatamente isso o que to querendo. Pois o usuário poderá digitar qualquer valor entre, por exemplo 50.000 à 2.000.000. E preciso que no exato momento que o usuário estiver digitando o valor, por exemplo ele vai colocar 1500000, apareça os pontos automaticamente, sem que o usuário precise adicionar o ponto.
Gostei + 0
25/11/2019
Julio Mendonça
no evento onkeyup do edit coloque o código abaixo:
procedure TFormContrato.edValorTotalKeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
var s: String;
begin
if (Key in [96..107]) or (Key in [48..57]) then
begin
S := edValorTotal.Text;
S := StringReplace(S,',','',[rfReplaceAll]);
S := StringReplace(S,'.','',[rfReplaceAll]);
if Length(s) = 3 then
begin
s := Copy(s,1,1)+','+Copy(S,2,15);
edValorTotal.Text := S;
edValorTotal.SelStart := Length(S);
end
else
if (Length(s) > 3) and (Length(s) < 6) then
begin
s := Copy(s,1,length(s)-2)+','+Copy(S,length(s)-1,15);
edValorTotal.Text := s;
edValorTotal.SelStart := Length(S);
end
else
if (Length(s) >= 6) and (Length(s) < 9) then
begin
s := Copy(s,1,length(s)-5)+'.'+Copy(s,length(s)-4,3)+','+Copy(S,length(s)-1,15);
edValorTotal.Text := s;
edValorTotal.SelStart := Length(S);
end
else
if (Length(s) >= 9) and (Length(s) < 12) then
begin
s := Copy(s,1,length(s)-8)+'.'+Copy(s,length(s)-7,3)+'.'+
Copy(s,length(s)-4,3)+','+Copy(S,length(s)-1,15);
edValorTotal.Text := s;
edValorTotal.SelStart := Length(S);
end
else
if (Length(s) >= 12) and (Length(s) < 15) then
begin
s := Copy(s,1,length(s)-11)+'.'+Copy(s,length(s)-10,3)+'.'+
Copy(s,length(s)-7,3)+'.'+Copy(s,length(s)-4,3)+','+Copy(S,length(s)-1,15);
edValorTotal.Text := s;
edValorTotal.SelStart := Length(S);
end;
end;
end;Gostei + 0
31/01/2021
Jefferson
no evento onkeyup do edit coloque o código abaixo:
procedure TFormContrato.edValorTotalKeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
var s: String;
begin
if (Key in [96..107]) or (Key in [48..57]) then
begin
S := edValorTotal.Text;
S := StringReplace(S,',','',[rfReplaceAll]);
S := StringReplace(S,'.','',[rfReplaceAll]);
if Length(s) = 3 then
begin
s := Copy(s,1,1)+','+Copy(S,2,15);
edValorTotal.Text := S;
edValorTotal.SelStart := Length(S);
end
else
if (Length(s) > 3) and (Length(s) < 6) then
begin
s := Copy(s,1,length(s)-2)+','+Copy(S,length(s)-1,15);
edValorTotal.Text := s;
edValorTotal.SelStart := Length(S);
end
else
if (Length(s) >= 6) and (Length(s) < 9) then
begin
s := Copy(s,1,length(s)-5)+'.'+Copy(s,length(s)-4,3)+','+Copy(S,length(s)-1,15);
edValorTotal.Text := s;
edValorTotal.SelStart := Length(S);
end
else
if (Length(s) >= 9) and (Length(s) < 12) then
begin
s := Copy(s,1,length(s)-8)+'.'+Copy(s,length(s)-7,3)+'.'+
Copy(s,length(s)-4,3)+','+Copy(S,length(s)-1,15);
edValorTotal.Text := s;
edValorTotal.SelStart := Length(S);
end
else
if (Length(s) >= 12) and (Length(s) < 15) then
begin
s := Copy(s,1,length(s)-11)+'.'+Copy(s,length(s)-10,3)+'.'+
Copy(s,length(s)-7,3)+'.'+Copy(s,length(s)-4,3)+','+Copy(S,length(s)-1,15);
edValorTotal.Text := s;
edValorTotal.SelStart := Length(S);
end;
end;
end;nice Lampião!!!
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)