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!

ROUND FUNCTION in Crystal Reports

Status
Not open for further replies.

ulicki

Technical User
Oct 24, 2001
88
US
Hi,

Version 7 Crystal. I am writing a report and using the ROUND function. I was having a problem when the rounded value should have equaled the end of a range.

So I create the following formula and place it in my report and it returns False.

round(10,4) = 10;

Has anyone seen this?

 
What do you mean by "should have equaled the end of a range"? What are you expecting to happen here? Where are you placing your formula? In what section of the report? Software Sales, Training, Implementation and Support for Exact Macola, eSynergy, and Crystal Reports
dgilsdorf@trianglepartners.com
 
Don's questions are to the point.

I think you mis-understand the ROUND function.

It is used to eliminate decimials.

So if x = 100.2345

Round(x,2) would equal 100.23
Round(x,3) would equal 100.235
round(x,0) would equal 100

Howard Hammerman,
Crystal Training and Crystal Material
On-site and public classes
Low-cost telephone/email support
FREE independent Crystal newsletter
howard@hammerman.com
800-783-2269
 
Hi,

Thanks for responding to my question.

I have a field price from the database and am determing what range of values it will fall into to create a total. I define the ranges in a formula I place in the report header. I get the values from a parameter. In the detail section I have a formula

if {@Option Price} in NumberVar Range range1 then {@Options Outstanding To Date} else 0;

The formula for {@Option Price} is
Round({gsumm_view.OPTION_PRICE},4);

The formula that declares the range is
NumberVar Range range1 := 0 to {?Price Ranges}[1];
0;

Now if I replace {@Option Price} with {gsumm_view.OPTION_PRICE} in the first formuala and for the case where {?Price Ranges}[1] = gsumm_view.OPTION_PRICE = 10 the formula evaluates true. If I use {@Option Price} the formula evaluates to false.

So I say to myself this does not make sense. So I query the database (Oracle 8i, column is NUMBER(30,15)) and my price comes back as 10. Now it makes less sense. So I say to myself something is wrong with the ROUND function. So I run a simple test on it ROUND(10,4) = 10 because this is what my if statement in my formula is doing and it returns false.
 
ROUND(10,4) = 10.0000
so
ROUND(10,4) = 10 is false.
--------------
Are you aware that:

NumberVar Range range1 := 0 to {?Price Ranges}[1];
0;

will always equal zero?



Howard Hammerman,
Crystal Training and Crystal Material
On-site and public classes
Low-cost telephone/email support
FREE independent Crystal newsletter
howard@hammerman.com
800-783-2269
 
Hi Howard,

Thank you for your response,

Yes I am aware that
NumberVar Range range1 := 0 to {?Price Ranges}[1];
0;
will return a zero. I actually define nine other ranges in this formula. And use them in the report. My understanding is that a formula must return a value and that you cannot just define a range, hence the need for the 0;. I do not use the formula in my code. Thank you for asking.

I understand your repsonse, however when I try
round(10,4) = 10.0000;
I still get false.
round(10.25,2) = 10.25; I get TRUE
round(10.25,4) = 10.25; I get FALSE
round(10,0) = 10; I get TRUE


If you are receiving the results I am then I think this is a bug in the way values are handled by the ROUND function.

However I am recommending to myself that if I compare a number that is rounded (using the round function) of x decimals I must round the value I am comparing it to to the same decimals.

What are your thoughts on this?

Again thank you for taking the time to dialog on this point.

Regards,

Mike
 
Mike,

I think you should move the ranges into the formula that uses them rather then specifiy them separately. But that is not your problem.

Your points are right on. I will investigate. Howard Hammerman,
Crystal Training and Crystal Material
On-site and public classes
Low-cost telephone/email support
FREE independent Crystal newsletter
howard@hammerman.com
800-783-2269
 
Hi Howard,

Thank you for taking the time. I thought I was going nuts.

Regards,

Mike
 
There seems to be a bug in Version 7 rounding.

The formula:

round(10,4) * 10000000

Returns:

100000000.0000000010

This doesn't happen in v8.5

Ken Hamady, On-site Custom Crystal Reports Training & Consulting
Public classes and individual training.
Expert's Guide to Formulas / Guide to Crystal in VB
- tek@kenhamady.com
 
Hi Ken,

Thank you for your response. And I just found out yesterday I am going to be using Version 7 for a long while :(
Oh well,

Mike
 
Here is a kludge that works:

Val (Totext (10,4)) = 10

Probably a hair slower to process, but accurate. Ken Hamady, On-site Custom Crystal Reports Training & Consulting
Public classes and individual training.
Expert's Guide to Formulas / Guide to Crystal in VB
- tek@kenhamady.com
 
Hi Ken,

Thanks,

I will give it a try.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top