Round Decimal

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
shiva459
Premium Member
Premium Member
Posts: 100
Joined: Wed Jun 11, 2003 1:49 am
Location: Bangalore

Round Decimal

Post 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
vmcburney
Participant
Posts: 3593
Joined: Thu Jan 23, 2003 5:25 pm
Location: Australia, Melbourne
Contact:

Post 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
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post 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
kduke
Charter Member
Charter Member
Posts: 5227
Joined: Thu May 29, 2003 9:47 am
Location: Dallas, TX
Contact:

Post 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
inter5566
Premium Member
Premium Member
Posts: 57
Joined: Tue Jun 10, 2003 1:51 pm
Location: US - Midwest

Post 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.
Post Reply