Focal Point
[CLOSED] How to make digit "5" to always be round up?

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

October 27, 2011, 05:10 PM
Emily Lee
[CLOSED] How to make digit "5" to always be round up?
Why when first digit to be dropped is 5, it sometimes get round up and somtimes get round down?

I read data from DB2 table, there 'Rate_A','Rate_B', 'Rate_C' defined as S9(1)V9(4) comp-3, which is one digit at left of the decimal point, 4 digits at right, and it is packed decimal.

First I read it from DB2 table, hold it as a hold file, define a new percentage field in the hold file by multiple it with 100. As:

DEFINE FILE DB2HOLD
Rate_A_Pecent/P7.4 = Rate_A * 100;
Rate_B_Pecent/P7.4 = Rate_B * 100;
Rate_C_Pecent/P7.4 = Rate_C * 100;

Then when I display, I only want to display one digit after decimal:

PRINT
Rate_A_Pecent/P7.1 AS "Rate_A %"
Rate_B_Pecent/P7.1 AS "Rate_B %"
Rate_C_Pecent/P7.1 AS "Rate_C %"

But the result, is not conistent, we found when the 2nd digit to be dropped is 5, it sometimes get round up and somtimes get round down. Any idea of why? or how to make it consistent? thanks,

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


WebFOCUS 8.2.01 AppStudio
HTML, PDF, Excel
October 28, 2011, 09:32 AM
Gizmo
I also came across this same issue this week in 7.7.02 when I was using a compute.

Instead of assigning the value to P7.2, try using D7.2 instead. Worked in my situation at least.



Windows: WF 7.6.2: SQL Server 2008 R2
October 28, 2011, 12:05 PM
Doug
PLease list your actual / raw data for these values for better analysis on our part...
Thanks, Doug
October 28, 2011, 04:10 PM
Emily Lee
The original value in DB2 table are :

Rate_A: 0.5175
Rate_B: 0.5035
Rate_C: 0.4685

After multiple with 100 in DEFINE FILE and PRINT with 1 decimal:
'Rate_A %' = 51.8
'Rate_B %' = 50.3
'Rate_C %' = 46.8

I have also tried with D7.4, D7.1, but the result has no difference.
thanks.
Emily - 7.6.11 mainframe


WebFOCUS 8.2.01 AppStudio
HTML, PDF, Excel
October 28, 2011, 04:29 PM
njsden
Can you also please display the ACTUAL and USAGE definition for those fields in the master file?

Please make sure to enclose that content in [ CODE ] tags for ease of reading. (See the </> button in the message's toolbar).



Prod/Dev: WF Server 8008/Win 2008 - WF Client 8008/Win 2008 - Dev. Studio: 8008/Windows 7 - DBMS: Oracle 11g Rel 2
Test: Dev. Studio 8008 /Windows 7 (Local) Output:HTML, EXL2K.
October 31, 2011, 02:52 PM
Mary Watermann
An old trick would be to add a small number to the RATE fields:

  
DEFINE FILE CAR
RATE_A/D7.4 = (0.5175 + .00001) * 100;
RATE_B/D7.4 = (0.5035 + .00001) * 100;
RATE_C/D7.4 = (0.4685 + .00001) * 100;
END
TABLE FILE CAR
PRINT
RATE_A/D7.1
RATE_B/D7.1
RATE_C/D7.1
DEALER_COST
BY COUNTRY
BY CAR
END



This worked in my test.


WF 7.6.10, Windows, PDF, Excel
November 01, 2011, 08:08 AM
George Patton
You could finesse Mary's technique by adding an IF statement to the effect that if the last digit is a 5 then increment the previous digit by 1.


WebFOCUS 7.7.05 Windows, Linux, DB2, IBM Lotus Notes, Firebird, Lotus Symphony/OpenOffice. Outputs PDF, Excel 2007 (for OpenOffice integration), WP
November 02, 2011, 10:04 AM
Ram Prasad E
Why this is happening? Here is the answer.

The decimal portion of a floating-point value as it is internally represented in
hexadecimal floating-point notation is repeating (that is, non-terminating), the repeating
hexadecimal number is resolved as a non-repeating slightly lower number, and this lower
number is stored as the field value.

While the original number, 1.15, would have been rounded upward to 1.2 (since the first
extra digit was 5 or greater), the number as stored is slightly less than 1.15 (1.149999)
and, as the first extra digit is now less than 5 (4 in this case), it is rounded down to 1.1.

Refer to "Describing Data With
WebFOCUS Language" --> Chapter - 4 Describing Individual Filed --> USAGE --> Rounding

Hope this helps.

Thanks,
Ram


WebFOCUS 8.1.05
Windows
http://ibiwebfocus.wordpress.com
https://www.facebook.com/groups/ibi.webfocus/