Page 1 of 1

trunc a decimal number to the X position

Posted: Wed Feb 03, 2010 2:48 pm
by Datamine
Hello Everyone,

I've tried to find it here but without luck, so here is my question,

i want to "trunc" a decimal number up to the 3rd position after the decimal separator, i don't want to round the number.

for example:
i have a decimal number --> 1785.65897
and i want the result to be --> 1785.658

what is the simplest why to accomplish it in Datastage?


thanks,
Datamine

Re: trunc a decimal number to the X position

Posted: Wed Feb 03, 2010 3:08 pm
by dganeshm
Two ways :

Change the precision of the decimal to n,3
Treat as a string , do a substring from 1 to index of 1st occurence of '.' + 3.

Posted: Thu Feb 04, 2010 1:06 am
by gaya3
you can use the oconv format function for decimal conversions.

Oconv(1234.567, "MD20T") will give 1234.56 without rounding off. Replace '2' in MD20T with the number of decimal places that you want in your output.

Posted: Thu Feb 04, 2010 3:18 am
by Datamine
o.k - thanks for the info,

can i also use the function FMT?

Posted: Thu Feb 04, 2010 4:13 am
by ArndW
I prefer "INT(In.NumberColumn/1000)*1000" to get 3 decimal positions.

Posted: Thu Feb 04, 2010 5:08 am
by Datamine
from a performance point of view, which one of the method mentioned above is the fastest?

Posted: Thu Feb 04, 2010 3:47 pm
by ray.wurlod
I believe that, of the options listed, Fmt() would be most efficient.