Page 1 of 1

Can we extract the decimal part alone using Iconv/Oconv

Posted: Mon May 23, 2005 2:59 am
by kruthika
Can we extract the decimal part alone using Iconv/Oconv.

I arrived at the solution by using the following code.
Substrings("3435.676",Index("3435.676",'.',1)+1,Len("3435.676"))
But it seems to be a round about.

Can we achieve the same using Iconv or Oconv....

Thanks

Posted: Mon May 23, 2005 3:13 am
by ArndW
Hello Kruthika,

although ICONV and OCONV are quite efficient functions, they are a bit too powerful for your specific request and will not be the most efficient. The INDEX function as you have used it is fast, you could also use the FIELD function if your number is in the format "nnnnn.dddd", i.e. FIELD(In.mynumber,'.',2) for that portion after the decimal.

You can also use the INT() function to strip off decimal portions or if you really wish to stick with ICONV/OCONV look at the MD conversion code description in the Basic User's Guide pages 819 onwards.

Re: Can we extract the decimal part alone using Iconv/Oconv

Posted: Mon May 23, 2005 3:18 am
by ArndW
kruthika wrote:Can we extract the decimal part alone using Iconv/Oconv.

I arrived at the solution by using the following code.
Substrings("3435.676",Index("3435.676",'.',1)+1,Len("3435.676"))
But it seems to be a round about.

Can we achieve the same using Iconv or Oconv....

Thanks
Sorry, I forgot to suggest a modification of what you did that would perform somewhat better:

In.MyNumberColumn[INDEX(In.MyNumberColumn,'.',1)+1,999]

The "999" is meant to be longer than the rest of the string, DS will stop parsing at the end of the string. This saves your LEN() call [which, if you wanted to be correct, needs to be decremented by your start position; but because DS does stop at the end of the string will work nonetheless :))

Posted: Mon May 23, 2005 3:38 am
by kruthika
Thanks Arnd...

Field function itself suits my need.