Focal Point
[SOLVED] Comparision of numeric fields not working as expected

This topic can be found at:
https://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/1567054776

July 27, 2015, 11:57 AM
Rifaz
[SOLVED] Comparision of numeric fields not working as expected
Hi,

I'm comparing the 2 numeric values, when there is a match I want to print the value in the report else blank.

DEFINE FILE US_ALL
XMTC/A64V = IF CNT EQ MID THEN METRICCATEGORY ELSE '';
END

Some of the comparisons are not working.

What could be the issue? Any ideas?

This message has been edited. Last edited by: Rifaz,


-Rifaz

WebFOCUS 7.7.x and 8.x
July 27, 2015, 12:19 PM
Prarie
Do the two fields have the exact same format? If not - you need to make them have the same format to compare.
July 27, 2015, 12:38 PM
John_Edwards
Step 1 is to not use a reserved word as a variable name. CNT in the middle of that source code is fraught with peril. If it's a database field I'd recommend aliasing it in the master file. I don't think that's your problem here, but you're poking the bear, and there's no good reason to poke the bear.

Step 2, if the number fields are integers, all should work correctly. If they are floats you'll find examples where 1 does not equal 1, because floating point numbers are evil and don't want you to be happy. It will show 1 in the report, but the machine's bit pattern will hold 1.000000000000000001 and you won't get exact equivalence.

Use Decimal values with specified tolerances to make sure you are comparing well-trimmed numbers. Also make sure both are of the same exact format to be sure.

J.

This message has been edited. Last edited by: John_Edwards,



July 27, 2015, 02:30 PM
Rifaz
Yes, both are same format.

What I'm trying to do,

TABLE FILE CAR
SUM 
COMPUTE MID/D3 =(CNT.CAR/2); 
BY COUNTRY
SUM 
COMPUTE CTR/D3=IF COUNTRY EQ LAST COUNTRY THEN CTR+1 ELSE 1;
BY COUNTRY
BY CAR
ON TABLE HOLD AS MAIN
ON TABLE SET HOLDLIST PRINTONLY
END
-RUN
DEFINE FILE MAIN
XCOUNTRY/A10=IF CTR EQ MID THEN COUNTRY ELSE '';
END
TABLE FILE MAIN
SUM MID CTR
BY COUNTRY NOPRINT
BY XCOUNTRY
BY CAR
END
-EXIT 

'
I want the XCOUNTRY to get displayed whenever there is a match


-Rifaz

WebFOCUS 7.7.x and 8.x
July 27, 2015, 02:40 PM
John_Edwards
Should

COMPUTE CTR/D3=IF COUNTRY EQ LAST COUNTRY THEN CTR+1 ELSE 1;

be

COMPUTE CTR/D3=IF COUNTRY EQ LAST COUNTRY THEN LAST CTR +1 ELSE 1;

by any chance? If not you'll always get the value 1 since you're summarizing by country. In fact I don't think that will matter. I think CTR will be 1 no matter what you have in your data. You need the second LAST in order to have your numbers count forward from 1.


I use something similar in DEFINE fields for Print reports, where you want the numbering to change every time a sorted field moves to the next value.

The COUNTRY comparison looks fine to me.



July 28, 2015, 12:12 AM
Rifaz
Thanks for the follow up John!
Suggested COMPUTE doesn't help me out.

Why 'ENGLAND' and 'FRANCE' is not showing up although it has a match in MID and CTR



I guess, figured it out, it's because of ENGLAND and FRANCE MID values are 1.5 and 0.5 internally, i intentionally rounded off the numbers to get it compare with CTR.

How to overcome this now?

This message has been edited. Last edited by: Rifaz,


-Rifaz

WebFOCUS 7.7.x and 8.x
July 28, 2015, 01:41 AM
Rifaz
Yes, It's resolved after converting the Decimal to Alpha using FTOA and get it compared. Sweating


-Rifaz

WebFOCUS 7.7.x and 8.x