Page 1 of 1

Round Decimal

Posted: Sun Jun 08, 2003 11:52 pm
by shiva459
Hi
I want to use a function which rounds off the decimal value to next higher value.I mean anything greater than 1(say1.1) should be rounded to 2.Is there any inbuilt function or i have to write a function to acheive this.
Regards
Shiva

Shivakumar

Posted: Mon Jun 09, 2003 3:14 am
by vmcburney
In a transformer reformat your input column to have 0 decimal places using the fmt function, this will execute a round to the nearest integer. Adjust the value up by .5 to ensure this always rounds up:
fmt(InputLink.MyValue+.5,"0")

Vincent McBurney
Data Integration Services
www.intramatix.com

Posted: Mon Jun 09, 2003 6:32 pm
by ray.wurlod
There are at least five ways to solve this one.
Probably the most efficient is to take the integer component then add one. For example:
Int(InLink.ColName)+1

If you want to preserve the fiction that it's a decimal, use:
Int(InLink.ColName)+1.0

(DataStage does implicit internal conversions automatically as necessary; both of the above approaches is equally valid.

Ray Wurlod
Education and Consulting Services
ABN 57 092 448 518

Posted: Tue Jun 10, 2003 7:19 am
by kduke
Shiva

Ray's way will take 0 and make it 1. I don't think that is what you want.

Int(InLink.ColName+0.5)

I think is more like a round function. Try it.

Thanks Kim.


Kim Duke
DwNav - ETL Navigator
www.Duke-Consulting.com

Posted: Tue Jun 10, 2003 12:29 pm
by inter5566
Just throwing in my 2cents.

Rounding, regardless of endpoints, requires logic to determine. Simple truncation alone can not be used for rounding. There is always a special case ie. it works for everything except 1.0 or 1.5, so logic is used to handle these cases. The fmt function mentions rounding in its help page, therefore if you don't want to implement an if then else structure you will need to use the fmt function. The numericround transformers all reference the fmt function internally, so Vincent's reply is probably the most efficient.

Edit-sorry for the mistake Vincent.