NumberVar Rounding/Integer Problem

We have an issue with a report that is returning the incorrect value.

We use the following formulas:

CALCVAR (Report Header1)
Whileprintingrecords;
Numbervar justabove;
justabove:= 0.1;

CALCANALYSIS (Report Header2)
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)

Please help, I am sure I must be doing something daft.
LVL 1
optimumreportsAsked:
Who is Participating?
 
peter57rConnect With a Mentor Commented:
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
 
mlmccConnect With a Mentor Commented:
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
 
James0628Connect With a Mentor Commented:
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
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
optimumreportsAuthor Commented:
Thanks guys...

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

Cheers,

Tom
0
 
optimumreportsAuthor Commented:
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
 
mlmccCommented:
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
 
James0628Commented:
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
 
optimumreportsAuthor Commented:
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
 
mlmccCommented:
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
 
optimumreportsAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.