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?
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?
0
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);
begin
  if DisplayText then
    Text := FormatFloat('#.00%', (Sender.AsFloat*100))
  else
    Text := FloatToStr(Sender.AsFloat*100);
end; 

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

Open in new window

...more
0

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 ... ?
0
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
Delphi

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.