rounding to lowest integer

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
news78
Participant
Posts: 44
Joined: Fri Jul 07, 2006 1:37 pm

rounding to lowest integer

Post by news78 »

Hello,

Is there any function (like floor) which will always round the parameter to closest LOWER integer? e.g. 6.5 > 6, 6.9 > 6, 0.1 > 0, 0.9 > 0?

I tried fmt() but it rounds both ways(higher & lower). I also tried using fmt(Arg1-0.5,"0") but it wont work for any value less than 0.5 (result gets negative).

Thanks for your help.

- vinay
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

Welcome Aboard :P
Use the Int() function.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
us1aslam1us
Charter Member
Charter Member
Posts: 822
Joined: Sat Sep 17, 2005 5:25 pm
Location: USA

Post by us1aslam1us »

Fmt() should also work.

Have you tried

Code: Select all

FMT(COL_NAME,"R2")
Sam
I_Server_Whale
Premium Member
Premium Member
Posts: 1255
Joined: Wed Feb 02, 2005 11:54 am
Location: United States of America

Post by I_Server_Whale »

us1aslam1us wrote:Fmt() should also work.

Have you tried

Code: Select all

FMT(COL_NAME,"R2")
Sam

Code: Select all

FMT(COL_NAME,"R2")
will not work.



news78 wrote: Is there any function (like floor) which will always round the parameter to closest LOWER integer? e.g. 6.5 > 6, 6.9 > 6, 0.1 > 0, 0.9 > 0?
Vinay,

you have mentioned about positive numbers but not about negative numbers.

Int() function alone on the field will get you the job done for positive numbers, but not for negative numbers.

Since, -2 is greater than -3. I'm assuming you would want the lower value which is -3.

Say, if you have the incoming value as -2.65.

If you are expecting the output as -2, then

Code: Select all


Int(InLink.InColumn)

will suffice. But if you are expecting -3, then use below code.

Code: Select all


If Arg1 > 0
Then 
Ans = Int(Arg1)
End
Else
Ans = Int(Arg1-1)
End

in a custom routine.

Or this in the derivation,

Code: Select all

If InLink.InColumn > 0
Then 
Int(InLink.InColumn)
Else
Int(InLink.InColumn-1)

Whale.
Anything that won't sell, I don't want to invent. Its sale is proof of utility, and utility is success.
Author: Thomas A. Edison 1847-1931, American Inventor, Entrepreneur, Founder of GE
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Sorry, Whale, Int() returns "the largest integer smaller than its argument".
Int(-2.65) returns -3.

So Int() is all the OP needs.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
I_Server_Whale
Premium Member
Premium Member
Posts: 1255
Joined: Wed Feb 02, 2005 11:54 am
Location: United States of America

Post by I_Server_Whale »

Ray,

I checked and Int(-2.65) returns -2 rather than -3.

Also, this what Datastage help says about it.

Code: Select all

Int Function

Returns the integer portion of a numeric expression.

Syntax 
Int (expression)

expression is a numeric expression. After evaluation, the fractional portion of the value is truncated and the integer portion is returned. If expression is a null value, null is returned.

Example
This example shows the integer portion of an expression being returned by the Int function:

MyValue = 2.3
IntValue = Int(MyValue)    ;* answer is 2
IntValue = Int(-MyValue)   ;* answer is -2
IntValue = Int(MyValue / 10)   ;* answer is 0


Thanks,
Whale.
Anything that won't sell, I don't want to invent. Its sale is proof of utility, and utility is success.
Author: Thomas A. Edison 1847-1931, American Inventor, Entrepreneur, Founder of GE
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

OK, g'donya for checking. I didn't. If I recall correctly, it's as I described in UniVerse. But I guess I ought to check that, too!
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
news78
Participant
Posts: 44
Joined: Fri Jul 07, 2006 1:37 pm

Post by news78 »

Thanks!
Post Reply