Displaying decimals

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
pedja2
Posts: 29
Joined: Thu 04 Jun 2009 11:11

Displaying decimals

Post by pedja2 » Thu 06 Mar 2014 20:30

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

Dimon
Devart Team
Posts: 2910
Joined: Mon 05 Mar 2007 16:32

Re: Displaying decimals

Post by Dimon » Fri 07 Mar 2014 09:49

Please clarify what do you mean by "mysql client query"?

pedja2
Posts: 29
Joined: Thu 04 Jun 2009 11:11

Re: Displaying decimals

Post by pedja2 » Fri 07 Mar 2014 09:54

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.

Dimon
Devart Team
Posts: 2910
Joined: Mon 05 Mar 2007 16:32

Re: Displaying decimals

Post by Dimon » Fri 07 Mar 2014 10:27

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.

pedja2
Posts: 29
Joined: Thu 04 Jun 2009 11:11

Re: Displaying decimals

Post by pedja2 » Fri 07 Mar 2014 10:33

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

Dimon
Devart Team
Posts: 2910
Joined: Mon 05 Mar 2007 16:32

Re: Displaying decimals

Post by Dimon » Fri 07 Mar 2014 14:12

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);

Post Reply