Page 1 of 1

Decimal problem

Posted: Tue 22 Sep 2009 11:47
by cxg417
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

Posted: Wed 23 Sep 2009 08:21
by Plash
The field scale is 2. So the value is rounded to 2 digits.

Posted: Wed 23 Sep 2009 09:00
by wjzws
Plash wrote:The field scale is 2. So the value is rounded to 2 digits.
but Should be rounded (0.19)

Posted: Wed 23 Sep 2009 09:00
by wjzws
Plash wrote:The field scale is 2. So the value is rounded to 2 digits.
but Should be rounded (0.19)

Posted: Thu 24 Sep 2009 07:33
by Plash
Computer rounding functions do not use this mathematical rule. See the description of the RoundTo function in the Delphi help.

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

Posted: Fri 25 Sep 2009 01:54
by wjzws
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

Posted: Mon 28 Sep 2009 10:21
by Plash
You should not rely on the ODAC behaviour because it is implementation dependent.

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