TAdvEdit: entering floats in scientific notation?

Hi there,

I'm using TadvEdit fields for presenting float values that are both computed and can be edited by the user. Because of the float numbers, it is EditType=etFloat and PrecisionDisplay=pdShortest.

Small numbers like "0.000000345" are displayed to "3.45E-007", which is a nice thing. However, a user can't enter "3.45E-007" by hand! When there is a need to copy&paste a small number given in scientific notation, he needs to convert it to the "0.000000345" variant, then paste it into the TAdvEdit, just to see it immediately converted back and displayed as his initial "3.45E-007".
Once entered, it is even possible to edit both parts (significand and exponent).

Currently there is no other EditType allowing to do this. So, a new "etScientific" would be very helpful here...

Please let me know if that could be considered!

Thanks in advance,
Friedrich

Good morning Friedrich,

try in this way.

in the AdvEdit.onenter event set AdvEdit.PrecisionDisplay:=pdNormal, in this way the

3.45E-007 is convertd to 0,000000345 + all 0 are needed to reach the precision number you are setted (i.e. if you set Precision:=20 you have 0,0000003450000000000)

When you exit on AdvEdit.onexit set Advedit.PrecisionDisplay:=pdShortest and you back to

3.45E-007.

Ofcourse, with little work you can delete all exceeded (unwanted) zero after last number.

Have a nice day

Daniele

Umm well, the point is that I and my users would very much like to directly enter "3.45E-007" into the control, which is rejected currently... It is already possible to edit, this is not the problem.

Displaying small numbers in scientific notation is a standard, so I like the fact that it is possible to display them like this in an AdvEdit control. It just makes little sense and can't be explained to a user, that  "3.45E-007" is rejected on entering, but can be edited inline once it is there!

Good morning Friedrich,

try this second way ... (all work around ...)

The trick works on the same way ...

You have TAdvEdit already setted.

On AdvEdit.Onter even set

procedure TForm1.Edt1Enter(Sender: TObject);

begin

Edt1.EditType:=etString;

end;

Be carefully .. now you have to parse for decimal, plus, minus and E chars.



when exit

procedure TForm1.Edt1Exit(Sender: TObject);

Var D : Double;

begin

D:=Strtofloat(edt1.text); // Conversion check, here you can have conversion error .. if any

Edt1.EditType:=etFloat; // Return to float

edt1.FloatValue:=D; // Set float

end;

Now you can edit number like 4,5E-007 or 0,00000045 (i don't know why if number is not so small ... remain in number and not in scentific, i.e. if you type 4,5E-002 when exit it's change into 0,045 ... may be local settings ..)



Have a nice day

Daniele

OK, will try this, it sounds feasible:-)

When the number is like 0,045 then this is a shorter display with less digits than the same number in scientific notation, which always has the "E-002" part in it...