Page 1 of 1

Verify if given string is of Decimal type or not

Posted: Sat Sep 22, 2018 5:33 am
by nitingupta
Hi All,
I need to validate a given string in DS server jobs. Check If the given string is decimal or not.For Parallel jobs i can use IsValid(Decimal[m,n],MyString) function in transformer stage, however in Server jobs i am not able to find anything similar to perform that. Can someone help me on that.

for e.g. Column1 - decimal[5,2]
Values to reject - 123.444, 1234.567
Values to pass - 123.45, -123.45

Thanks,
Nitin Gupta

Posted: Sat Sep 22, 2018 7:42 am
by chulett
You would have to roll your own, typically in a custom BASIC routine. Been a while but thinking perhaps ICONV with an MD conversion code then check the status of the result? That or just wait for Ray to wander by and chime in. :wink:

Posted: Sat Sep 22, 2018 12:00 pm
by nitingupta
Thanks craig, I am trying with ICONV and MD conversion but not yet getting desired results. Meanwhile i will keep digging in it. If any other suggestions there please let me know.

Posted: Sun Sep 23, 2018 5:55 am
by chulett
Whatever you do, don't "test" this using a job but rather the build-in testing capability of the routine editor. Keep it simple so you can rapidly throw many different input strings into it then pass out the status of the conversion as the "answer". And in case you've not used it before, you would use the STATUS function to check the success of the conversion.

Posted: Mon Sep 24, 2018 12:20 am
by ray.wurlod
Num() function will report whether the value is numeric. That may suffice for your subject requirement. It even handles scientific notation, such as 6.023E23.

It seems, however, that you are interested in answering the question "is this a decimal number with exactly five significant digits and exactly two decimal places?". The Matches operator is our friend here.

Code: Select all

Ans = (inLink.TheString Matches "3N'.'2N")

Posted: Mon Sep 24, 2018 6:17 am
by nitingupta
Thanks Ray and Craig for your valuable inputs. I have implemented the logic by creating routine using NUM() and Iconv with MD and its working as expected. :-)