Is there a function to convert a string into a number ?

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
Inquisitive
Charter Member
Charter Member
Posts: 88
Joined: Tue Jan 13, 2004 3:07 pm

Is there a function to convert a string into a number ?

Post by Inquisitive »

I need to convert a string into a number. This is needed for performing a mod operation.
roy
Participant
Posts: 2598
Joined: Wed Jul 30, 2003 2:05 am
Location: Israel

Post by roy »

Hi,
Basically DS is type free, meaning that if you take a string and put it in a phrase of numeric meaning it will work if you enshure that it is numeric castable (a number in fact) in a transformer for example.
though types are checked when you read/write data from/into you sources/targets.
IHTH
Roy R.
Time is money but when you don't have money time is all you can afford.

Search before posting:)

Join the DataStagers team effort at:
http://www.worldcommunitygrid.org
Image
1stpoint
Participant
Posts: 165
Joined: Thu Nov 13, 2003 2:10 pm
Contact:

not necessarily true

Post by 1stpoint »

I wrote a VAL function a few years back.

It will convert things like "1.244E10", "$5767.88" and other non numeric fields to number.
Teej
Participant
Posts: 677
Joined: Fri Aug 08, 2003 9:26 am
Location: USA

Re: Is there a function to convert a string into a number ?

Post by Teej »

Inquisitive wrote:I need to convert a string into a number. This is needed for performing a mod operation.
Therefore, you are asking if you need to convert from a string to an integer. Not necessary -- as others have said, DataStage is MOSTLY type-independent. Just lets the mod function rip.

Naturally, you need to ensure that your data is validated as an integer in advance.

However, if you want a decimal values, just use StringToDecimal().

-T.J.
Developer of DataStage Parallel Engine (Orchestrate).
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

If you're using a BASIC Transformer stage (or are in a server job), you can use a BASIC expression. The easiest way is to perform some arithmetic. But you have to be certain that what you're beginning with can be regarded as numeric.

Code: Select all

If Num(inlink.column) Then Iconv(inlink.column,"MD0") Else 0
The Iconv function will remove thousands delimiters and currency symbol. It will also round to the indicated number of decimal places and NOT return the decimal place holder character. Find out all about the "MD" conversion in on-line help from Designer or Manager.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
bigpoppa
Participant
Posts: 190
Joined: Fri Feb 28, 2003 11:39 am

Is there a function to convert a string into a number ?

Post by bigpoppa »

PX is not freely-typed b/c it doesn't operate on DS's Basic engine. It uses a separate c-based engine.

I don't know the answer to the original question, but if someone has the APT_Ref cards, could they be kind enough to see if there is a str_to_num function for the APT_String class?

Thanks,
BP
Teej
Participant
Posts: 677
Joined: Fri Aug 08, 2003 9:26 am
Location: USA

Re: Is there a function to convert a string into a number ?

Post by Teej »

bigpoppa wrote:I don't know the answer to the original question, but if someone has the APT_Ref cards, could they be kind enough to see if there is a str_to_num function for the APT_String class?
There is an "asInteger(APT_Int32, APT_Status)" within APT_String class.

However, what the person would want is a APT_FieldConversion - there's tons of conversion options in it.

This is referring to Orchestrate HTML 6.0 version.

-T.J.
Developer of DataStage Parallel Engine (Orchestrate).
Post Reply