Focal Point
Round up to next whole number

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

November 21, 2007, 11:19 AM
mark66
Round up to next whole number
Hi all,

I need the result of a calculation to always round up to the next whole number.

Example: I need to work out how many weeks a given number of days spanned:

So I need 22/7 to equal 4 not 3.14285 or 3.

Thanks

Mark


WebFocus 765. iSeries v5r4
November 21, 2007, 11:31 AM
Prarie
This is an IBI example

DEFINE FILE CAR
ROUND1/D10.2 = RCOST/1000;
ROUND2/D5= INT(ROUND1+1) ;
END
TABLE FILE CAR
PRINT CAR RCOST ROUND1 ROUND2
END


In Focus since 1993. WebFOCUS 7.7.03 Win 2003
Looks as if you need to do some math figuring, if you calculate in decimal mode add .9 to the answer and then convert the output to integer which truncates would that work? In math terms

3.12285 + .9 = 4.02285 integer is 4
3.5 + .9 = 4.5 integer is 4

might work for you.


Leah
Many thanks Prarie & Leah.

Looks like you both came along at the same time with different solution, both of which work great for me.

I knew it would be something simple, but I was getting hung up on the ROUND function.

Thanks again Smiler


WebFocus 765. iSeries v5r4
Mark,
If you always want to round up then you have to beware of two possibilities:
1. your number is a whole number to begin with
2. your number is slightly over a whole number.
I suggest, if your original field is FIELD/D8.2:
WFIELD/D8=INT(FIELD);
UPFIELD/D8=IF FIELD EQ WFIELD THEN FIELD ELSE WFIELD + 1;



Daniel
In Focus since 1982
wf 8.202M/Win10/IIS/SSA - WrapApp Front End for WF

Thanks Danny,

I hadn't spotted that. 7 รท 1 was equal to 2, not 1. Now corrected.


WebFocus 765. iSeries v5r4
I might consider a refinement
use one of the MOD functions (DMOD,FMOD,IMOD)
to determine whether or not your remainder really is zero.
Just comparing the FIELD to the WFIELD
isn't quite reliable, because that FIELD may appear to be 8.0 and its integer value ,8, would equal WFIELD, however these D fields carry decimal leave-behinds way down in the 32nd digit (or however far they really go internally ) so a MOD of FIELD/WFIELD will either equal 0 if they are truly equal
or not 0, if they're even a negligible bit off.




In Focus since 1979///7706m/5 ;wintel 2008/64;OAM security; Oracle db, ///MRE/BID
Try
xdefine/d8.2 = database_field + .05;
ydefine/d8 = int(xdefine);


ira w. 5.3.6 aix 533


aix-533,websphere 5.1.1,apache-2.0,
wf 538(d), 537 (p),
==============
7.6.11 (t) aix 5312
websphere 6.1.19
apache 2.0