Page 1 of 1

Rounding off to Nearst Integer Please Help Me...

Posted: Fri Jul 25, 2003 12:24 am
by devaraj4u
Dear All,

In my project I am Subtracting 2 dates.I have ValueDate and MaturityDate So I m doing MaturityDate - ValueDate So that i will get difference in Days.My Business Requirement needs the difference in Months So what i did approxiately (MDATE - VDATE) / 30 So i m getting Difference in Months.But if u concern the output value it will be a Real/Decimal Value.

Example

ValueDate ---> 27/Feb/2003
MaturityDate ---> 27/Mar/2003

So (MDate - Vdate) ---> 28 Days (Diff in Days)
(MDate - Vdate)/30 ---> 0.93 (Diff in Months)...

I am getting the desired result as 0.93.
But the Need is,it need to be rouded off to the nearest interger.

Example

If the Range is like 0.5 To 0.99 it should rounded to 1.

In my case I need the output as '1' rather than 0.93 coz nearst integer is '1'

So I need the Function which will similar to Round() or CEIL() which is there in VB or Excel Tools.

I tried using INT() Function in DataStage it is simply truncating the decimal and returning me '0' for '0.9'.

Please can anybody help me...

Thanks & Regards,
K.S.Rajan.

Posted: Fri Jul 25, 2003 12:50 am
by ray.wurlod
Try INT(value+0.5) or OCONV(value, "MD0").
The second specifies "masked decimal, 0 decimal places, rounding". To get truncation it would be OCONV(value, "MD0T").


Ray Wurlod
Education and Consulting Services
ABN 57 092 448 518

Posted: Fri Jul 25, 2003 1:17 am
by devaraj4u
Dear Ray,

Thanks for your Timely Help.The Int(Value+0.5) worked well sir.

Thanks & Regars,
K.S.Rajan.

Posted: Fri Jul 25, 2003 3:20 am
by degraciavg
Hi Rajan,

Another altenative is to use the FMT() function, e.g.

FMT(DateDiff, 0)

Cheers,
Vladimir

vladimir