Focal Point Banner
Community Center Education Summit Technical Support User Groups
Let's Get Social!

Facebook Twitter LinkedIn YouTube
Go
New
Search
Notify
Tools
Reply
  
ROUNDING FUNCTION
 Login/Join
 
Platinum Member
posted
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
 
Posts: 188 | Registered: April 14, 2005Reply With QuoteReport This Post
Virtuoso
posted Hide Post
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
 
Posts: 1317 | Location: Council Bluffs, IA | Registered: May 24, 2004Reply With QuoteReport This Post
Virtuoso
posted Hide Post
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
 
Posts: 1903 | Location: San Antonio | Registered: February 28, 2005Reply With QuoteReport This Post
Platinum Member
posted Hide Post
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
 
Posts: 188 | Registered: April 14, 2005Reply With QuoteReport This Post
Virtuoso
posted Hide Post
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
 
Posts: 2298 | Location: Salt Lake City, Utah | Registered: February 02, 2007Reply With QuoteReport This Post
Expert
posted Hide Post
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
 
Posts: 3811 | Location: Manhattan | Registered: October 28, 2003Reply With QuoteReport This Post
  Powered by Social Strata  
 


Copyright © 1996-2018 Information Builders, leaders in enterprise business intelligence.