 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Kevin Guest
|
Posted: Fri Feb 20, 2004 4:00 am Post subject: Decimal Poblem of TBCDField |
|
|
Hi ,
I have a Decimal Problem in D5, i have a Table in MSSQL200, which have a
Field Decimal(5,2) and then the Delphi will gen a TBCDField. When i input
1.535 in a TDbEdit, it will show 1.54 but input 1.545 it will show 1.54. If
input 1.555 , it will show 1.56 but 1.565 will show 1.56. Why it will have
this Problem and how to solve it ?
Thanks
Kevin
|
|
| Back to top |
|
 |
John Herbster (TeamB) Guest
|
Posted: Fri Feb 20, 2004 3:00 pm Post subject: Re: Decimal Poblem of TBCDField |
|
|
"Kevin" <sysrhy (AT) netvigator (DOT) com> wrote
| Quote: | ... I have a Table in MSSQL200, which have a
field Decimal(5,2) [for which] Delphi will gen a
TBCDField. When I input 1.535 in a TDbEdit,
it will show 1.54 but ...
|
Kevin, Please do not depend on the database manager
to make those critical rounding decisions. You have
very little control over how it will do it. Instead do
your own rounding before you post your data. For
doing this you might find my decimal rounding routines
that are available from Code Central useful. These
routines allow you to specify about 9 kinds of decimal
fraction rounding. Regards, JohnH
Ref http://tinyurl.com/5bpq which is short for
http://codecentral.borland.com/codecentral/ccweb.exe/listing?id=17998
|
|
| Back to top |
|
 |
Kevin Guest
|
Posted: Sat Feb 21, 2004 2:43 am Post subject: Re: Decimal Poblem of TBCDField |
|
|
Thanks John. But Can u give me a example how to use that Function in my
Case, i have try but doesn't Success.
Thanks Again
Kevin
"John Herbster (TeamB)" <herb-sci1_AT_sbcglobal.net> wrote
| Quote: |
"Kevin" <sysrhy (AT) netvigator (DOT) com> wrote
... I have a Table in MSSQL200, which have a
field Decimal(5,2) [for which] Delphi will gen a
TBCDField. When I input 1.535 in a TDbEdit,
it will show 1.54 but ...
Kevin, Please do not depend on the database manager
to make those critical rounding decisions. You have
very little control over how it will do it. Instead do
your own rounding before you post your data. For
doing this you might find my decimal rounding routines
that are available from Code Central useful. These
routines allow you to specify about 9 kinds of decimal
fraction rounding. Regards, JohnH
Ref http://tinyurl.com/5bpq which is short for
http://codecentral.borland.com/codecentral/ccweb.exe/listing?id=17998
|
|
|
| Back to top |
|
 |
John Herbster (TeamB) Guest
|
Posted: Sat Feb 21, 2004 4:11 am Post subject: Re: Decimal Poblem of TBCDField |
|
|
"Kevin" <sysrhy (AT) netvigator (DOT) com> wrote
| Quote: | Thanks John. But can you give me a example how
to use that Function in my Case, I have tried but
without Success.
|
Kevin, In the field's OnValidate event add code like this:
procedure TForm1.MyTable1MyField1Validate(Sender: TField);
begin
With Sender as TBCDField do
Value := DecimalRoundDbl(Value,2,drHalfUp);
end;
Here, from the DecimalRount_JH0 module, are the
available rounding controls:
drHalfEven,{Round to nearest or to even
whole number. (a.k.a Bankers) }
drHalfPos, {Round to nearest or toward positive.}
drHalfNeg, {Round to nearest or toward negative.}
drHalfDown,{Round to nearest or toward zero.}
drHalfUp, {Round to nearest or away from zero.}
drRndNeg, {Round toward negative. (a.k.a. Floor) }
drRndPos, {Round toward positive. (a.k.a. Ceil ) }
drRndDown, {Round toward zero. (a.k.a. Trunc) }
drRndUp); {Round away from zero.}
I hope that this helps. Regards, JohnH
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|