Display number value as Scientific Notation in a dbgrid

We display scientific data in a dbgrid. If the numeric value is outside the bounds (<.0001 and >10000.00), the number is displayed in Scientific Notation,otherwise it is displayed as a regular float. The field needs to be editable as either a float or scientific notation (the user must be able to enter an 'E+' or 'E-'.

We have attempted to use getText (testing the bounds then setting the format), it went into a recursive loop. We then tried the Validate which performed the conversion (adding 3 to the exponent (BAD)) and then set the format for ALL the rows in the column, even those that fell in the bounds (BAD), to sci-note.

value sci-note should be
.005 -> 5.e-006 0.005
.0000000006 6E-13 6.00 E-10

The value is stored in Oracle as a NUMBER. Oracle(TOAD) displays the value correctly for sci-note and float.

It worked in the OLD C++Builder without any fuss.
Scientific numbers must be precise if we have to manually process the number each time, we may loose something (significant digits) in the translation.

What do we do?
We have XE4, TMS Component Pack, FireDac and Oracle
LVL 1
Columbia EnergyEngineers of All TypesAsked:
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.

George TokasCommented:
DBGrid should be associated with a dataset component.
On this dataset in the Fields editor select the fields you want and apply DisplayFormat for scientific from associate Attributes.
It should change the display format in the dbgrid

George Tokas.
0
Columbia EnergyEngineers of All TypesAuthor Commented:
We did try that. It changed all the values in the column to scientific notation. However, The displayed values were erroneous. As I described in my original post, a value entered of .005 was displayed as 5.E-6 which is equivalent to .000005 it should have displayed as 5.E-3. The value displayed is off by 1000 PERCENT.  This is unacceptable to our customers.

The only solution we have come up with, so far, is to hover a TEdit box over the cell when in edit mode and use a calculated field, where we set the formatted value, for display. This however is causing other Error-causing issues (record has been updated by another user, the grid turning black(?)) where exiting/canceling is our only option.
0
Columbia EnergyEngineers of All TypesAuthor Commented:
We submitted the error to Embarcadero. They have acknowledged it as a bug as of XE7.  We decided to utilize TMS' DBAdvGrid.

Embarcadero provided a work around.
~~Go to source of DataModule and add the following code to the very bottom:

//---------------------------------------------------------------------------
void __fastcall TPDDM::FDTable1NUMBER2GetText(TField *Sender, UnicodeString &Text,
		  bool DisplayText)
{
  TBcd bcd;
  TValueBuffer Buffer;
  double dbl;
  Buffer.Length = sizeof(TBcd);

  if (Sender->GetData(Buffer, True))
  {
	bcd = TBitConverter::ToBcd(Buffer);
	dbl = BcdToDouble(bcd);
	Text = FormatFloat(FDTable1NUMBER2->DisplayFormat, dbl);
  }
  else
	Text = "";
}
//---------------------------------------------------------------------------

~~Switch to Form Designer in DataModule
~~Right-click FDTable1 and pick "Fields Editor"
~~In Fields Editor select your NUMBER2 field ~~In the Object Inspector switch to Events tab ~~Click the drop down on OnGetText event and select FDTable1NUMBER2GetText

Open in new window

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
Columbia EnergyEngineers of All TypesAuthor Commented:
We had to submit the error to Embarcadero for a solution. We find that while the work around works, it is inefficient. The issue is glaring in the face of scientific data. We discovered the error in version XE4 and it had not been corrected by XE7.
0
Columbia EnergyEngineers of All TypesAuthor Commented:
We have confirmed with Embarcadero that this issue is still outstanding in XE8.
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
C++

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.