rounding to lowest integer
Moderators: chulett, rschirm, roy
rounding to lowest integer
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
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
-
- Charter Member
- Posts: 822
- Joined: Sat Sep 17, 2005 5:25 pm
- Location: USA
-
- Premium Member
- Posts: 1255
- Joined: Wed Feb 02, 2005 11:54 am
- Location: United States of America
Code: Select all
FMT(COL_NAME,"R2")
Vinay,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?
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)
Code: Select all
If Arg1 > 0
Then
Ans = Int(Arg1)
End
Else
Ans = Int(Arg1-1)
End
Or this in the derivation,
Code: Select all
If InLink.InColumn > 0
Then
Int(InLink.InColumn)
Else
Int(InLink.InColumn-1)
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
Author: Thomas A. Edison 1847-1931, American Inventor, Entrepreneur, Founder of GE
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
-
- Premium Member
- Posts: 1255
- Joined: Wed Feb 02, 2005 11:54 am
- Location: United States of America
Ray,
I checked and Int(-2.65) returns -2 rather than -3.
Also, this what Datastage help says about it.
Thanks,
Whale.
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
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
Author: Thomas A. Edison 1847-1931, American Inventor, Entrepreneur, Founder of GE
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact: