Jump to content

DecimalSeparator field type in a numeric (float)?


belo

Recommended Posts

How do I change the decimal points to commas in a field type numeric (float)?

 

Example VCL:

 

procedure TFrmCadNotalFiscal.UniDBEdit1KeyPress(Sender: TObject; var Key: Char);
begin
  if Key = '.' then
    Key := DecimalSeparator; // ','
end;
 
Does anyone have any concrete example of how to solve these problems with viewing and editing numeric fields?
 
Masks such as:  # # #, # # #, # #0.00 do not work for editing WebMode.
 
Any solution?
Link to comment
Share on other sites

Bom dia Eduardo eu utilizo uma função para isso:

 

Obs: Isso Para o Banco MYSQL

 

No evento OnExit:

FormataValor(TuniEdit1.Text);

function FormataValor(edit:TuniEdit):String;
var
   s : string;
   v : double;
   I : integer;
begin
  try
   if edit.Text = EmptyStr then
      edit.Text := '0';

   {obter o texto do edit, SEM o ponto decimal}
   s := '';
   for I := 1 to length(edit.Text) do
   if (edit.Text[I] in ['0'..'9',',']) then
      s := s + edit.Text[I];

   if s = EmptyStr then
      s := '0';

   {fazer com que o conteúdo do edit apresente 2 casas decimais}
   v := strtofloat(s);

   {Formata o valor de (V) para aceitar valores do tipo 0,10}
   edit.Text := FormatFloat('0.00',v);

   edit.Color  := clWhite;
   except
    on e: exception do
      begin
        ShowMessage('Este Campo só é permitido números.');
        edit.Text   := EmptyStr;
        edit.Color  := clYellow;
        edit.SetFocus;
      end;
  end;
Link to comment
Share on other sites

Olá Marlon!

 

Aqui não funcionou. Ao chamar FormataValor(UniEdit1.Text) dá o erro:

 

E2010 Incompatible Types: 'TUniEdit' and 'TCaption'

 

Alterei para FormataValor(UniEdit1) e passou, mas não está formatando:

 

Se por exemplo faço: 100,50 retorna 10050,00

 

O que pode ser?

 

Outra coisa, se for utilizar TUniDBEdit com campo Float dá o erro:

is not a Valid BCD Value 

 

Obrigado por ajudar.

Link to comment
Share on other sites

Referente ao Erro:

 

"E2010 Incompatible Types: 'TUniEdit' and 'TCaption'"

 

voce deve apenas colocar o "Tuniedit1" sem o Caption ou Text.

 

Ex: FormataValor(Uniedit1);

 

 

"se for utilizar TUniDBEdit"

 

quando voce tem TuniDBEdit, voce deve utilizar da seguinte forma:

 

FormataValor(TUniEdit(UNIDBEDTI1));

 

Att, Marlon Nardi

Link to comment
Share on other sites

Referente ao Erro:

 

"E2010 Incompatible Types: 'TUniEdit' and 'TCaption'"

 

voce deve apenas colocar o "Tuniedit1" sem o Caption ou Text.

 

Ex: FormataValor(Uniedit1);

 

 

"se for utilizar TUniDBEdit"

 

quando voce tem TuniDBEdit, voce deve utilizar da seguinte forma:

 

FormataValor(TUniEdit(UNIDBEDTI1));

 

Att, Marlon Nardi

 

I still have the same problem (Continuo com o mesmo problema).

 

Any other tips? (Alguma outra dica?)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...