Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 4 of 4 total
Thread Five decimal Places
Thu, Nov 15 2007 4:57 AMPermanent Link

MCourt
D7+4.24

I have 2 fields that are DECIMAL with dimension 4. They are a RATE and a QUANTITY. The result is a £xx.xx and it all works fine.
BUT now my client wants the quantity to be 5 decimal places for QUANTITY so that they can accurately get figures such as the example below:

RATE= £5000 QTY=2.31175     COST= 50000x2.31175  = £115587.50

BUT obviously the current QTY is rounded up to 2.3118 = £115590.00 or if it's rounded down  £115585.00

In the datagrid it works great at the moment for 4dp's, if a user enters 1.234567890 and they come off the cell it adjusts to 4dp perfect.

But now I need a 5dp solution so using DECIMAL (BCD) is not an option as it has a maximum of 4dp precision.

Do i change the QTY to a FLOAT datatype? I did a small experiment and used #.##### as the format string it displayed fine in the datagrid but still rounded to 4dp in the
result, is this due to how I did the calculation using the OnCalcFields handler:

procedure Trwdm.tblTempOrdCalcFields(DataSet: TDataSet);
begin

   Dataset['CostA']:=Dataset['Quantity']*Dataset['Rate'] (works prerfect when using 2 DECIMAL fields at 4 precison, but change QTY to float and still teh float as a 4dp)
end;

This is still giving me 4dp result for quantity even though Quantity has now been changed to a Float, thus the total result which is a currency of 2dp is still incorrect. Do I need
to do some type casting or floatTo function to get my result.

Regards
Mark

Thu, Nov 15 2007 4:25 PMPermanent Link

"Rita"
Hi Mark float maybe the way to go I'am struggling with
a similair prob I use formatcurr() as below.
formatfloat() would be ok for me also but I do get a rounding
prob I cant figure out

sST := formatcurr('#,###,###.##',nST);
sST := formatcurr('#,###,###.##0',nST);


I will post a working exe in binaries and u will see what I mean.
Rita

"MCourt" <core.tech@ukonline.co.uk> wrote in message
news:A681453F-3F3E-4C33-AEFF-F455833FD0B2@news.elevatesoft.com...
> D7+4.24
>
> I have 2 fields that are DECIMAL with dimension 4. They are a RATE and a
> QUANTITY. The result is a £xx.xx and it all works fine.
> BUT now my client wants the quantity to be 5 decimal places for QUANTITY
> so that they can accurately get figures such as the example below:
>
> RATE= £5000 QTY=2.31175     COST= 50000x2.31175  = £115587.50
>
> BUT obviously the current QTY is rounded up to 2.3118 = £115590.00 or if
> it's rounded down  £115585.00
>
> In the datagrid it works great at the moment for 4dp's, if a user enters
> 1.234567890 and they come off the cell it adjusts to 4dp perfect.
>
> But now I need a 5dp solution so using DECIMAL (BCD) is not an option as
> it has a maximum of 4dp precision.
>
> Do i change the QTY to a FLOAT datatype? I did a small experiment and used
> #.##### as the format string it displayed fine in the datagrid but still
> rounded to 4dp in the
> result, is this due to how I did the calculation using the OnCalcFields
> handler:
>
> procedure Trwdm.tblTempOrdCalcFields(DataSet: TDataSet);
> begin
>
>    Dataset['CostA']:=Dataset['Quantity']*Dataset['Rate'] (works prerfect
> when using 2 DECIMAL fields at 4 precison, but change QTY to float and
> still teh float as a 4dp)
> end;
>
> This is still giving me 4dp result for quantity even though Quantity has
> now been changed to a Float, thus the total result which is a currency of
> 2dp is still incorrect. Do I need
> to do some type casting or floatTo function to get my result.
>
> Regards
> Mark
>
>


Thu, Nov 15 2007 4:54 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Mark,

<< This is still giving me 4dp result for quantity even though Quantity has
now been changed to a Float, thus the total result which is a currency of
2dp is still incorrect. Do I need to do some type casting or floatTo
function to get my result. >>

Yes, if you cast the BCD column value (currency) to a float
(double/extended) in the calculation, you should get the desired result.
The compiler is probably treating the result as a currency value
(BCD/decimal) and not a double/extended value.

--
Tim Young
Elevate Software
www.elevatesoft.com

Fri, Nov 16 2007 10:01 AMPermanent Link

Sean McCall
I've always been able to solve money rounding issues by doing the
calculation in floating point and then assigning the value to a currency
type variable. One in the currency variable I round that.

Rita wrote:
> Hi Mark float maybe the way to go I'am struggling with
> a similair prob I use formatcurr() as below.
> formatfloat() would be ok for me also but I do get a rounding
> prob I cant figure out
>
> sST := formatcurr('#,###,###.##',nST);
> sST := formatcurr('#,###,###.##0',nST);
>
>
> I will post a working exe in binaries and u will see what I mean.
> Rita
>
> "MCourt" <core.tech@ukonline.co.uk> wrote in message
> news:A681453F-3F3E-4C33-AEFF-F455833FD0B2@news.elevatesoft.com...
>> D7+4.24
>>
>> I have 2 fields that are DECIMAL with dimension 4. They are a RATE and a
>> QUANTITY. The result is a £xx.xx and it all works fine.
>> BUT now my client wants the quantity to be 5 decimal places for QUANTITY
>> so that they can accurately get figures such as the example below:
>>
>> RATE= £5000 QTY=2.31175     COST= 50000x2.31175  = £115587.50
>>
>> BUT obviously the current QTY is rounded up to 2.3118 = £115590.00 or if
>> it's rounded down  £115585.00
>>
>> In the datagrid it works great at the moment for 4dp's, if a user enters
>> 1.234567890 and they come off the cell it adjusts to 4dp perfect.
>>
>> But now I need a 5dp solution so using DECIMAL (BCD) is not an option as
>> it has a maximum of 4dp precision.
>>
>> Do i change the QTY to a FLOAT datatype? I did a small experiment and used
>> #.##### as the format string it displayed fine in the datagrid but still
>> rounded to 4dp in the
>> result, is this due to how I did the calculation using the OnCalcFields
>> handler:
>>
>> procedure Trwdm.tblTempOrdCalcFields(DataSet: TDataSet);
>> begin
>>
>>    Dataset['CostA']:=Dataset['Quantity']*Dataset['Rate'] (works prerfect
>> when using 2 DECIMAL fields at 4 precison, but change QTY to float and
>> still teh float as a 4dp)
>> end;
>>
>> This is still giving me 4dp result for quantity even though Quantity has
>> now been changed to a Float, thus the total result which is a currency of
>> 2dp is still incorrect. Do I need
>> to do some type casting or floatTo function to get my result.
>>
>> Regards
>> Mark
>>
>>
>
>
>
Image