Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 107
  • Last Modified:

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
0
Columbia Energy
Asked:
Columbia Energy
  • 4
1 Solution
 
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
 
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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now