Link to home
Start Free TrialLog in
Avatar of Columbia Energy
Columbia EnergyFlag for United States of America

asked on

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
Avatar of George Tokas
George Tokas
Flag of Greece image

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.
Avatar of Columbia Energy

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of Columbia Energy
Columbia Energy
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
We have confirmed with Embarcadero that this issue is still outstanding in XE8.