Zeos + Lazarus + Firebird - Numbers < 10 with 2 decimals

In this forum we will discuss things relating the ZEOSLib 6.6.x stable versions

Moderators: gto, EgonHugeist

Post Reply
Mando
Fresh Boarder
Fresh Boarder
Posts: 16
Joined: 15.09.2010, 12:32

Zeos + Lazarus + Firebird - Numbers < 10 with 2 decimals

Post by Mando »

Hi.
I'm newer with zeos in lazarus and firebird.
I've a table with a numeric (decial, float, double ...) field. I post into it a value less than 10 with a 2 (or more) decimals (p.e. 5.92) and the value is posted right in the table, but the control (aka TDBEdit, TDBGrid) doesn't reflect the correct value, it shows the value without last decimal. (p.e 5.92 -> 5.9). That doesn't occurr with values greater than or equal to 10.
I know I can play with precission in the field definition, but I'm developing a Database administration utility, and I open the tables dinamically.

Is that a bug? zeos 7 alpha has the same behavior than 6.6 stable.
What can i do to solve it ?

SQLdb works properly.


Thanks, regards from Spain.

(excuse my english)
guidoaerts
Senior Boarder
Senior Boarder
Posts: 93
Joined: 01.07.2009, 16:07

Post by guidoaerts »

change the displayformat property of the numeric field
for example : TFloatField.DisplayFormat := '0000.00'

Guido
Mando
Fresh Boarder
Fresh Boarder
Posts: 16
Joined: 15.09.2010, 12:32

Post by Mando »

Thanks for your response, guidoaerts. But I'm creating several Tztable and query components dinamically, and I don't want to do the fields definition
manually. Is there another way to solve this?


Thanks in advance.
guidoaerts
Senior Boarder
Senior Boarder
Posts: 93
Joined: 01.07.2009, 16:07

Post by guidoaerts »

I think you can change these properties dynamically after creating the components.

var
i: integer;

with TZTable.create do
begin
Connection := 'YourZConnection';
TableName := 'YourTable';
open;

for i := 0 to FieldCount-1 do
begin
if Fields.FieldKind = fkData then if Fields.DataType =ftFloat then
TFloatField(Fields).DisplayFormat := '0000.000';
end;
end;

Guido
Mando
Fresh Boarder
Fresh Boarder
Posts: 16
Joined: 15.09.2010, 12:32

Post by Mando »

Thanks, Guido, for your response. That is not exactly I'm looking for, but is a good porvisional solution.
However, this would be the right DisplayFormat: '0.00'. Only one zero in the left side and the required zeros in the right side. Also we can use the format char '#' to specify optionals spaces for decimals.
Example:
(0.00 ) 5.923 -> 5.92 , 8.6 -> 8.60
(0.0##) 5.923 -> 5.923, 8.6 -> 8.6

Thanks again.
Post Reply