Solved

Display number value as Scientific Notation in a dbgrid

Posted on 2014-09-22
5
76 Views
Last Modified: 2015-07-20
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
Comment
Question by:Columbia Energy
  • 4
5 Comments
 
LVL 16

Expert Comment

by:George Tokas
ID: 40342116
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
 
LVL 1

Author Comment

by:Columbia Energy
ID: 40342191
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
 
LVL 1

Accepted Solution

by:
Columbia Energy earned 0 total points
ID: 40758871
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
 
LVL 1

Author Closing Comment

by:Columbia Energy
ID: 40768193
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
 
LVL 1

Author Comment

by:Columbia Energy
ID: 40890667
We have confirmed with Embarcadero that this issue is still outstanding in XE8.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now