String to Number

A forum for discussing DataStage<sup>®</sup> basics. If you're not sure where your question goes, start here.

Moderators: chulett, rschirm, roy

Post Reply
dsdeveloper123
Participant
Posts: 33
Joined: Sun Jun 24, 2007 9:46 pm

String to Number

Post by dsdeveloper123 »

Hi all,

I have a string "-65".
In the transformer I want to do a mathematical operation on this string.
So I need to convert this string into number. How do I handle negative sign. Will DS function StringToDecimal work?
How do I accomplish this ?javascript:emoticon(':roll:')
Rolling Eyes

Thank u
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

Even though DS will do an implicit conversion from string to number in a transform stage, it is much better to explicitly convert using a function such as StringToDecimal(), which will take care of the sign.
dsdeveloper123
Participant
Posts: 33
Joined: Sun Jun 24, 2007 9:46 pm

Post by dsdeveloper123 »

Thank ...

This partially solves my problem...
Actually the data coming in is "- 65" (there is space in between the negative sign and the number)
I tried Trim() but it doesn't work
dsdeveloper123
Participant
Posts: 33
Joined: Sun Jun 24, 2007 9:46 pm

Post by dsdeveloper123 »

I got the Solution to my problem. I need to do StripWhiteSpace javascript:emoticon(':D')
Very Happy
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

Good job!
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

The overhead of invoking a JVM for every row is probably something you don't want. Prefer

Code: Select all

Convert(" ", "", InLink.TheNumericString)
If you're happy that you have a solution, please mark the thread as Resolved.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
dsdeveloper123
Participant
Posts: 33
Joined: Sun Jun 24, 2007 9:46 pm

Post by dsdeveloper123 »

I tried convert.
The problem is if I have a decimal value, something like "- 65.70"
Convert(" ", "", InLink.TheNumericString) is giving me "-66" as the output but where as StripWhiteSpaces is giving me "-65.70"
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

Convert() will not round, this is being done elsewhere. What is the defined datatype of the column or stage variable or derivation where you are doing thsi?
Post Reply