BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Decimal Poblem of TBCDField

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (ADO)
View previous topic :: View next topic  
Author Message
Kevin
Guest





PostPosted: Fri Feb 20, 2004 4:00 am    Post subject: Decimal Poblem of TBCDField Reply with quote



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





PostPosted: Fri Feb 20, 2004 3:00 pm    Post subject: Re: Decimal Poblem of TBCDField Reply with quote



"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





PostPosted: Sat Feb 21, 2004 2:43 am    Post subject: Re: Decimal Poblem of TBCDField Reply with quote



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





PostPosted: Sat Feb 21, 2004 4:11 am    Post subject: Re: Decimal Poblem of TBCDField Reply with quote


"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
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (ADO) All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.