Page 1 of 1

Displaying decimals

Posted: Thu 06 Mar 2014 20:30
by pedja2
Hallo,

when i use in the mysql client query

Code: Select all

select round(10.1,2)
it returns 10.10. In Mydac the same query returns 10.1.
How can i fix this?

Thanks

Re: Displaying decimals

Posted: Fri 07 Mar 2014 09:49
by Dimon
Please clarify what do you mean by "mysql client query"?

Re: Displaying decimals

Posted: Fri 07 Mar 2014 09:54
by pedja2
I mean "mysql client" mysql.exe which is deliverd with mysql server.
Also Heidsql en other clients works on the correct way. Only mydac do not show 2 decimals.

Re: Displaying decimals

Posted: Fri 07 Mar 2014 10:27
by Dimon
You can solve the issue in two ways.

1. Set the TMyQuery.Options.FieldsAsString property to True. At that, all the fields are mapped as string (a native MySQL format). MySQL client works in this way.

2. Set the TMyConnection.Options.NumericType property to ntFmtBCD. After this, create persistent fields in the dataset, and set the TField.DisplayFormat property to the '#.00' value.

Re: Displaying decimals

Posted: Fri 07 Mar 2014 10:33
by pedja2
Not really solutions:

1) creats all string fields, so numbers are left aligned

2) user can input own queries so creating persistent fields is not possible

Re: Displaying decimals

Posted: Fri 07 Mar 2014 14:12
by Dimon
1) MySQL client works in this way, and only therefore it can show numbers in this format.

2) You can do it without creating persistent fields. You can generate DisplayFormat automatically in run time in the following way:

Code: Select all

  MyQuery.Open;
  (MyQuery.Fields[0] as TFMTBCDField).DisplayFormat := '#.' + StringOfChar('0', (MyQuery.Fields[0] as TFMTBCDField).Size);