Link to home
Start Free TrialLog in
Avatar of Norm-al
Norm-alFlag for United States of America

asked on

How to format DBTextEdit (float field) as a percent?

I have a data entry form that has a DBTextEdit field pulling in a float but when I show the form, it needs to show as a percentage. I have this same field in a grid and the procedure I have is the following:

if (AText <> NULL) OR (AText <> '') then begin
    AText := FloatToStr(StrToFloatDef(AText,0) * 100);
    AText := AText + '%';
  end;

I tried this in both the OnValidate and OnNewLookupDisplayText and those did not work... any ideas how to accomplish this? I'm sure it will be simple and I am just overlooking something really silly... thanks for your help!
Avatar of Ferruccio Accalai
Ferruccio Accalai
Flag of Italy image

You should use field.ongettext

if (AText <> NULL) OR (AText <> '') then begin
    AText := FormatFloat('#,### %',(StrToFloatDef(AText,0) * 100));

Avatar of Norm-al

ASKER

I dont have an event for OnGetText for the DBTextEdit, I only have that in the grid.
I was meaning in the Table.field.ongettext
Avatar of Norm-al

ASKER

Oh ok... I already have that procedure for the field in the table but I need to also format to percent for the field that is not in the table, it is just an edit box on a form.
What is the class of the component?
ASKER CERTIFIED SOLUTION
Avatar of Mahdi78
Mahdi78
Flag of Algeria image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Norm-al

ASKER

Worked great, thanks!