Focal Point
ROUNDING FUNCTION

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

October 12, 2007, 01:55 PM
Bethany
ROUNDING FUNCTION
I thought I found rounding function (ROUND(infield, number, outfield) in another posting. Can someone let me now how this function works? I'm trying to round a number to the nearest 5.

Thanks,
Bethany

WF 7.1.3
DevStudio 7.1.4


Server Environment: Win2K3 Server WebFOCUS 7.13 Apache Tomcat standalone application server
October 12, 2007, 02:29 PM
Leah
I'm not familiar with a ROUND function, are you trying to round numbers that are defined with decimal places already? If so it's been my experience that FOCUS does round. If it's integers that is a 'horse of a different color' as they say. Those truncate as the normal processing.


Leah
October 12, 2007, 02:45 PM
Prarie
This is all the documentation says
The following example rounds up cents to one decimal place:

TABLE FILE EMPLOYEE
PRINT DED_AMT AND
COMPUTE ROUND_DED/D12.2 = ROUND(DED_AMT, 1, ROUND_DED);
WHERE DED_AMT LT 20;
END


In Focus since 1993. WebFOCUS 7.7.03 Win 2003
Is there a function that allow you to round a number to the nearest 5? If the number is 127.33 then you'd round down to 125.00, or if you had 188.2 then you'd round up to 190.00?


Server Environment: Win2K3 Server WebFOCUS 7.13 Apache Tomcat standalone application server
There isn't a function to do that, but you could do it with an easy DEFINE or COMPUTE:

DEFINE FILE CAR
RCOSTDIV5/P12=RCOST/5;
RCOSTRND5/D12=RCOSTDIV5*5;
END
TABLE FILE CAR
PRINT CAR RCOST RCOSTDIV5 RCOSTRND5
END

The value of the first field must be packed (vs. integer or floating) in order to round correctly. This is because I truncates and D or F stores decimals internally so no rounding would occur.

The field RCOSTRND5 is rounded to the nearest 5.


Regards,

Darin



In FOCUS since 1991
WF Server: 7.7.04 on Linux and Z/OS, ReportCaster, Self-Service, MRE, Java, Flex
Data: DB2/UDB, Adabas, SQL Server Output: HTML,PDF,EXL2K/07, PS, AHTML, Flex
WF Client: 77 on Linux w/Tomcat
and to take Darin's idea one step further
define a function and put it in your edasprof so its available to you whenever you need it.
DEFINE FUNCTION F_FIVES(INPUT/D7.2)
temp/P7=INPUT/5 ;
F_FIVES/D7.2=temp*5; 
END

-* now this function is available to any fex
without having to code it every time
DEFINE FILE CAR 
FIRST/D7.2 WITH COUNTRY = 124.33 ;
SECOND/D7.2=F_FIVES(FIRST);
END
-RUN
TABLE FILE CAR
PRINT FIRST   SECOND     
END

Expand the concept, if you routinely round to other multiples;
DEFINE FUNCTION F_MROUND(INPUT/D7.2,TUPLES/I1)
temp/P7=INPUT/TUPLES ;
F_MROUND/D7.2=temp*TUPLES; 
END

MROUND being a microsoft word, and therefore perhaps consistent w/ memory.
and then the syntax to use it..
NEWNUMBER/D7.2=F_MROUND(oldnumber,5);

note: I've adopted Tony's suggestion that we use the syntax F_ to begin all our functions.
Also have alook at the IMOD function, and its partners, DMOD, etc. Might give you ideas for the future; I used to use these MOD functions to do rounding, but Darin's way is *so* much cooler. Thanx Darin

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




In Focus since 1979///7706m/5 ;wintel 2008/64;OAM security; Oracle db, ///MRE/BID