Percentage in DbGrid ; three state needed

Using Delphi xe8 and UniDac i want three versions ( hypostasis ?) of percentage:

(1) In the database as float: 0.072
(2) Displayed in the tDbgrid as "7,20%"
(3) When i edit as "7,2"

1 and 2 is no problem. I just put the code :
Text:=FormatFloat('#.00%', (Sender.AsFloat*100));

Open in new window

in the gettext event for the tField. But how do i get (3) for editing in the DbGrid?
Paer ToernellAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Paer ToernellAuthor Commented:
The problem probably is, how do i change the value in a DBGRID cell when i enter that cell?
Sinisa VukSoftware architectCommented:
set OnGetText event for that field:

//somewhere after open:
Qry1.FieldByName('Percent').OnGetText := Qry1PercentGetText;
Qry1.FieldByName('Percent').OnSetText := Qry1PercentSetText;
procedure TForm1.Qry1PercentGetText(Sender: TField; var Text: string;
  DisplayText: Boolean);
  if DisplayText then
    Text := FormatFloat('#.00%', (Sender.AsFloat*100))
    Text := FloatToStr(Sender.AsFloat*100);

procedure TForm1.Qry1PercentSetText(Sender: TField; const Text: String);
  Sender.AsFloat := StrToFloatDef(Text, 0)/100; 

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Geert GOracle dbaCommented:
sunsales ... this site is to help you with coding
not just give you the solution on a silver platter

what have you got so far ... ?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.