Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Formula Rounding

Status
Not open for further replies.

smitty206

Programmer
Jan 24, 2002
5
CA
I was wondering if someone has experienced this problem, and come up with a possible work around.

Problem:
I have created a formula in the detail section to calculate a discount. In this case the number calculated out to 194.205. I then passed the number to the group footer for displaying and it reads 194.20. In our system the number is displayed as 194.21, which is correct from a math point of view, were it is rounded up on 5. In this case by simply passing the variable it will only round up on 6. I have tried doing this with just straight numbers and passing other calculated formula values and it works fine, but just in this case it will not.

If anyone else has worked around this could you please let me know.

Thanks in advance



 
Alternatively, you could right click the field, go into Format, hit Customize, and ensure that the Round option is set to .01

Naith
 
Are you sure that the nderlying value is .205?
It might be something like .2048 .
This would show .205 at 3 decimlas but round down at 2 decimals. Ken Hamady, On-site Custom Crystal Reports Training & Consulting
Public classes and individual training.
Guide to using Crystal in VB
tek@kenhamady.com
 
I have tried with setting the decimals and rounding as far out as I could, with the same results. For some reason the formula that I am using,(which I thought basic as far as formula calculations go) is causing this to happen.

Below is a copy of the formula;

Shared NumberVar ExtAmt := 0;
Shared NumberVar NetAmt := 0;
Shared NumberVar Discount := 0;
Shared NumberVar SubTotal;
Shared NumberVar Tax1Total;
Shared NumberVar Tax2Total;
Shared NumberVar Tax3Total;
Shared NumberVar Tax4Total;
Shared NumberVar DiscountTotal;
Shared NumberVar NetSubTotal;
Shared NumberVar Counter;


Counter := Counter + 1;
ExtAmt := {OFARLIN_DBM.SellUnitPrice} * {OFARLIN_DBM.SellShipQuantity};
Discount := ExtAmt * ({OFARLIN_DBM.DiscountPercent} / 100 );
NetAmt := ExtAmt - Discount;
DiscountTotal := DiscountTotal + Discount;
Tax1Total := Tax1Total + {OFARLIN_DBM.TaxLevel1};
Tax2Total := Tax2Total + {OFARLIN_DBM.TaxLevel2};
Tax3Total := Tax3Total + {OFARLIN_DBM.TaxLevel3};
Tax4Total := Tax4Total + {OFARLIN_DBM.TaxLevel4};
SubTotal := SubTotal + ExtAmt;

It is the line with the calculation for Discount that when passed down as a shared variable, casues the problem.

Thanks for your responses.

Smitty
 
I think you want to set the rounding further IN, not further OUT. What happens if you round the discount variable to 2 decimals at the time it is assigned? Ken Hamady, On-site Custom Crystal Reports Training & Consulting
Public classes and individual training.
Guide to using Crystal in VB
tek@kenhamady.com
 
I agree with Ken. If you wait until later to round the discount then your discount totals and NetAmt will not add up properly.

eg discounts running discount total
1.025 1.025
2.048 3.073
1.011 4.084 ... rounded to 2 decimals 4.08

rounded discounts total = 1.03 + 2.05 + 1.01 = 4.09

so I would chnage this line to

Discount := round(ExtAmt * ({OFARLIN_DBM.DiscountPercent} / 100 ),2);
Jim Broadbent
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top