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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Rounding with Variable Decimal Place 1

Status
Not open for further replies.

N11689

Programmer
Jan 29, 2002
113
US
We are rounding a formula based on an input parameter (decimal precision) from the main report, but it is not working. The decimal precision options are either 2 or 3 decimal places, so we are passing a 2 or 3.

We are passing this input parameter through to the subreport as Shared Numbervar DecimalPrecision.

I have created a formula in the subreport for a Local NumberVar DecimalPrecision1 and am making that equal to the Shared NumberVar DecimalPrecision that we've passed through from the main report.

I have a second formula in the subreport where we are multiplying a sell amount * tax amount. We then are rounding to the decimal precision passed through (in this case we are using our NumberVar DecimalPrecision1).

The result is that the formula is rounding to the nearest whole number, not to the nearest decimal precision.

We have also tried this, and we've gotten closer, but it will work rounding one way, but not the other.

In the formula where we multiply the sell amount * tax amount, that's all we do, we do not round.
We then format the formula field (customize) and conditionally (x-2) set the decimal places to NumberVar DecimalPrecision1. And, conditionally round (x-2) the field to NumberVar DecimalPrecision1.

The fields look okay in the subreport, but then when we add up the total tax, we are off by a penny.
We are adding up this formula field using a running total, and then formatting it the same way...to round and set decimal places conditionally based on NumberVar DecimalPrecision1.

It seems to work fine this way if we are calculating based on 3 decimal places.
However, when we are set to 2 decimal places, it seems like the formula is totalling the tax using 3 decimal places and then rounding. Thus we are off by a penny.

Example:
Tax Amount(3) Tax Amount(2)
7.243 7.24
4.564 4.56
Total Is: 11.807 11.81
Total Should Be: 11.807 11.80

Can anyone explain how I can get around this problem?
Thank you.
 
Rather than summing the rounded number, sum the actual number.

Then in lieu of using the rounding on the number, just display a totext formula, as in:

whileprintingrecords;
shared numbervar Passdecimalplaces := Passdecimalplaces;
totext(table,number,Passdecimalplaces)

Might simplify life for you.

-k
 
My understanding is that you would like to sum the rounded number. My guess is that formatting the field only affects the display, not the calculations. You probably need to use the parameter to determine what values are added, as in:

if {?precision} = 2 then round({table.tax},2) else
{table.tax}

Then use this formula in your running total.

-LB
 
We would definitely like to sum the rounded figure. We have tried this, and the formula always seesm to calculate the 'else'. It seems that Crystal does not recognize the {?precision} input parameter (that we have defined as NumberVar DecimalPrecision1.

if {?precision} = 2 then round({table.tax},2) else
{table.tax}

If you can help to determine why it 'ignores' the variable we have defined that might help.

In the meantime, I will try the following to see what results I get.

whileprintingrecords;
shared numbervar Passdecimalplaces := Passdecimalplaces;
totext(table,number,Passdecimalplaces)

Thanks
 
You need to share the formula you are using for NumberVar DecimalPrecision1.

-LB
 
That won't sum the rounded number.

Though you might sum this with better success:

whileprintingrecords;
shared numbervar Passdecimalplaces := Passdecimalplaces;
tonumber(totext(table,number,Passdecimalplaces))

-k
 
Shouldn't the "whileprintingrecords" be changed to "whilereadingrecords"? I don't think you can include a 2nd pass formula in a Running Total (if you're actually using the RT Expert).
 
Good point, FV, if it's to be used in a RT.

Not sure why it should be though, they should be able to just right click it and select insert summary.

But the syntax is wrong:

whileprintingrecords;
shared numbervar Passdecimalplaces := Passdecimalplaces;
tonumber(totext({table.number},Passdecimalplaces))

Had an errant comma and no braces.

-k
 
Well, I beg to differ, but I don't believe you can do Insert Summary on a 2nd pass formula, either. In fact, Insert doesn't even show up on the short-cut menu option when you right-click on a 2nd pass formula. Am I missing something?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top