|Home » Technical Support » DBISAM Technical Support » Support Forums » DBISAM General » View Thread|
|Messages 1 to 5 of 5 total|
|TBCD / TCurrency bug ....Any ideas?|
|Thu, Nov 7 2019 10:21 AM||Permanent Link|
My environment: Delphi Berlin(latest update, DBisam(Latest update), Windows 10.
So I am having an issue with a simple calculation:
I have defined a DBisam field as BCD, size 2
In code I perform a simple multipication.
To keep it simple and to illustrate I am using numbers in the assignment but other variations with fields also display incorrect value.
datafrm.tbTranDetail.FieldByName('TD_TRAN_PRODUCT_SELLING_PRICE_INC_VAT').AsBCD:=2.98 * 1.20;
// THIS EVALUATES TO 3.57 ... BUT SHOULD BE 3.58
I hear that there are issues with the TBCD, TCurrency types across different versions of Delphi compilers.
( I am unable to test this as I am on Delphi Berlin )
I chose BCD as its supposed to be more accurate;
I would expect that to be the case as they are of a financial nature.
Any work around or suggestions ?
|Thu, Nov 7 2019 10:45 AM||Permanent Link|
If your field is currency then one common approach is to store the amount in then minor unit ie in your case rather than hold 3.58 you'd hold 358. The other thing you could do is carry out the rounding yourself, even going back into the dim and distant past where the approach was add 0.5 and truncate
I was going to say it was probably due to bankers rounding but refreshing my memory says that's not the case, but you might like to have a look at this
just in case it has relevance
|Fri, Nov 8 2019 7:50 AM||Permanent Link|
Tactical Business Corporation
If you want more accuracy use more decimals and control your rounding when you want to output less decimals.
There is no perfect solution.
|Fri, Nov 8 2019 1:58 PM||Permanent Link|
It's important that you post the exact code and types and not a simplification.
Aslo, not knowing the exact details, I suggest that you try FieldByName(...).AsCurrency instead of .AsBCD and see what happens.
|Wed, Nov 13 2019 9:09 AM||Permanent Link|
Thanks for suggestions.. I will dig into further. Thanks