Decimal problem

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
cxg417
Posts: 41
Joined: Thu 26 Mar 2009 08:07

Decimal problem

Post by cxg417 » Tue 22 Sep 2009 11:47

Please note the following code

var
fPrice:Currency;
begin
//UniDAC
fZJE:=0.185;
UniQuery1.Append;
UniQuery1.FieldByName('fPrice').AsCurrency:=fPrice;
ShowMessage(FloatToStr(UniQuery1.FieldByName('fPrice').AsCurrency));
//Result is 0.18

//ADO
ADOQuery1.Append;
ADOQuery1.FieldByName('fPrice').AsCurrency:=fPrice;
ShowMessage(FloatToStr(ADOQuery1.FieldByName('fPrice').AsCurrency));
//Result is 0.185

//BDE
Query1.Append;
Query1.FieldByName('fPrice').AsCurrency:=fPrice;
ShowMessage(FloatToStr(Query1.FieldByName('fPrice').AsCurrency));
//Result is 0.19

//fPrice FieldType is Numeric(12,2)
________
Apple games
Last edited by cxg417 on Tue 15 Feb 2011 14:57, edited 1 time in total.

Plash
Devart Team
Posts: 2844
Joined: Wed 10 May 2006 07:09

Post by Plash » Wed 23 Sep 2009 08:21

The field scale is 2. So the value is rounded to 2 digits.

wjzws
Posts: 20
Joined: Fri 17 Jul 2009 02:33

Post by wjzws » Wed 23 Sep 2009 09:00

Plash wrote:The field scale is 2. So the value is rounded to 2 digits.
but Should be rounded (0.19)

wjzws
Posts: 20
Joined: Fri 17 Jul 2009 02:33

Post by wjzws » Wed 23 Sep 2009 09:00

Plash wrote:The field scale is 2. So the value is rounded to 2 digits.
but Should be rounded (0.19)

Plash
Devart Team
Posts: 2844
Joined: Wed 10 May 2006 07:09

Post by Plash » Thu 24 Sep 2009 07:33

Computer rounding functions do not use this mathematical rule. See the description of the RoundTo function in the Delphi help.

wjzws
Posts: 20
Joined: Fri 17 Jul 2009 02:33

f we can add an attribute as an option is equal to 0.18 or 0

Post by wjzws » Fri 25 Sep 2009 01:54

Yes! Delphi sure there is such a treatment!

However, in general we all hoped that the outcome is equal to = 0.19.

I think that if we can add an attribute as an option is equal to 0.18 or 0.19 is not better?

For example: default is 0.19, you can also choose to use delphi algorithm 0.19

Plash
Devart Team
Posts: 2844
Joined: Wed 10 May 2006 07:09

Post by Plash » Mon 28 Sep 2009 10:21

You should not rely on the ODAC behaviour because it is implementation dependent.

You should round values yourself if it is important for you.

Post Reply