Go Premium for a chance to win a PS4. Enter to Win

x
Solved

# NumberVar Rounding/Integer Problem

Posted on 2010-11-23
Medium Priority
1,843 Views
We have an issue with a report that is returning the incorrect value.

We use the following formulas:

Whileprintingrecords;
Numbervar justabove;
justabove:= 0.1;

Whileprintingrecords;
Numbervar justabove;
Stringvar analysis;
If {field1} – {field2} >= just above then analysis:= “just below average”
Note: (The mathematical calculation of the two fields is 0.1)

DISPLAYANALYSIS (Report Footer 1)
Whileprintingrecords;
Stringvar analysis;

When DISPLAYANALYSIS is used in the report it returns nothing.
Is this something to do with rounding? Or using numbvar to store 0.1 as it works with other numbers such as 1.5 (if I change justabove:= 0.1 to justabove:= 0.5 and update the database fields to match)

0
Question by:optimumreports
• 4
• 3
• 2
• +1

LVL 77

Accepted Solution

peter57r earned 800 total points
ID: 34196047
It's not obvious to me that it's a precision problem although i won't rule it out because accuracy of decimals is always a potential issue.

Perhaps it would be worth testing a variation of this. Set justabove to 1 and do..

If int({field1}*10) – int({field2}*10) >= justabove then analysis:= “just below average”
0

LVL 101

Assisted Solution

mlmcc earned 600 total points
ID: 34197202
I suspect it is a rounding issue.  remember computers use base 2 or binary.  This limits the values that can be displayed/saved as exact values.

0.1 cannot be saved exactly so I think you are getting a round problem

One way to check would be as peter suggests.

mlmcc
0

LVL 35

Assisted Solution

James0628 earned 600 total points
ID: 34203400
FWIW, I did a couple of quick tests and your formulas seem to work fine here.  i wouldn't really expect precision to be a problem, unless your values are unusually large, or have a lot of decimal places.

I'd try changing the last line in the second formula to just

{field1} - {field2}

and see what you get.

James
0

LVL 1

Author Comment

ID: 34204465
Thanks guys...

We'll test this this afternoon and feedback to you all.

Cheers,

Tom
0

LVL 1

Author Comment

ID: 34231190
Many thanks for the suggestions sorry for my slow delay in getting back to you.

I have tried the following as suggested but it still returns blank data:

1

whileprintingrecords;
Numbervar justabove;

justabove:= 1; // Set from 0.1 to 1 as suggested

2

whileprintingrecords;
numbervar justabove;

stringvar holding_Writing;

if {KS1_All.Writing Significant} = true and {KS1_All.Writing APS} > {National_All.Writing APS} then holding_Writing:= "significantly above"
else if {KS1_All.Writing Significant} = true and {KS1_All.Writing APS} < {National_All.Writing APS} then holding_Writing:= "significantly below"
else

(
if  int({KS1_All.Writing APS}*10) - int({National_All.Writing APS}*10)  >= justabove then holding_Writing:= "just above"
);

Any ideas?

Tom
0

LVL 101

Expert Comment

ID: 34231706
Does the report show the values of the fields being used?
If not can you put them on the report and show us what you are getting

mlmcc
0

LVL 35

Expert Comment

ID: 34236617
Or, as I suggested before, just change the last line in your second formula to {field1} - {field2}.  The point of that is to see the actual value that CR is getting from that calculation.  Of course the assumption there is that the result of that formula is visible on the report (not in a suppressed field or section).  And you may need/want to change the field format to show more decimal places, to get a more precise view of the value.

James
0

LVL 1

Author Comment

ID: 34248822
Hi all,

When we use the following integer formula it returns the data correctly which is great:

if  int({KS1_All.Writing APS}*10) - int({National_All.Writing APS}*10)  >= justabove then holding_Writing:= "just above"

However, now the integer formula is working when mutiplying by 10, I would just like to to confirm if the precision problem identified would affect any of the following variables or is it just where it is 0.1 and -0.1?

verysigabove:=3
sigabove:=2
wellabove:=1
above:=0.5
justabove:=1 \\previuously 0.1
verysigbelow:=-3
sigbelow:=-2
wellbelow:=-1
below:=-0.5
justbelow:=-1 \\previuously -0.1
inline:=0

Or will I need to mutiply all instances by 10?

Cheers,

Tom
0

LVL 101

Expert Comment

ID: 34249150
Since integers can be represent exactly it shouldn't affect any of them.  Even .5 is represented exactly so that should be ok

mlmcc
0

LVL 1

Author Closing Comment

ID: 34284013
Thanks for the feedback. Sorry we didnt get straight back to you all - we are really busy here at the moment.

Thanks again for your help - much appreciated.
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Crystal Reports: 5 Tests for Top Performance It is complete, your masterpiece report.  Not only does it meet your customer’s expectations, it blows them out the water, all they want is beautifully summarised and displayed in a myriad of ways. …
Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearly…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…