Number Formatting

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
JezT
Participant
Posts: 75
Joined: Wed Sep 15, 2004 1:52 am

Number Formatting

Post by JezT »

I am needing to convert two type of numbers within a DS Server job.

Firstly, I need to convert a number (e.g. 5.5) to the following format - NNNN.NNNN (in other words 5.5 would equal 0005.5000.

Secondly, I need to convert a number (e.e. 15.50) to the following format - NNNNNNNNNNNNNNNNNN (in other words 15.50 would equal 000000000000001550.

And finally, if my number is negative, how do I ensure that the '-' sign appears at the front ? I other words, -5.5 appears as -0005.5000 and not 000-5.5000.

Any suggestions ?
kumar_s
Charter Member
Charter Member
Posts: 5245
Joined: Thu Jun 16, 2005 11:00 pm

Post by kumar_s »

You are talking about the data type Decimal and Integer for you two cases in the order.
Impossible doesn't mean 'it is not possible' actually means... 'NOBODY HAS DONE IT SO FAR'
sb_akarmarkar
Participant
Posts: 232
Joined: Fri Sep 30, 2005 4:52 am
Contact:

Post by sb_akarmarkar »

Use field and Concatenation

Thanks,
Anupam
kumar_s
Charter Member
Charter Member
Posts: 5245
Joined: Thu Jun 16, 2005 11:00 pm

Post by kumar_s »

Decimal has first bit as sign bit.
Impossible doesn't mean 'it is not possible' actually means... 'NOBODY HAS DONE IT SO FAR'
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

You can use the FMT function, check your online help. Off the top of my head there may not be a formatting option for a leading minus sign. If not, simply check if your value is < 0 and concatenate it on the front of your output field if so.
-craig

"You can never have too many knives" -- Logan Nine Fingers
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Forgot to mention that 'FMT' will handle both of your examples: the zero padding and the 'descaling' of the decimal point.
-craig

"You can never have too many knives" -- Logan Nine Fingers
JezT
Participant
Posts: 75
Joined: Wed Sep 15, 2004 1:52 am

Post by JezT »

Thanks for the advice.

Have managed to sort out the 18 character field removing the decimal point but am having problems with the other issue.

Basically how to convert a value such as 72.19 to 0072.1900 or 0.03 to 0000.0300.
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

Use field along with the fmt function. Basically strip the contents before and after the decimal point, format it using the fmt function and then concatenate it back together. Not a very sleek solution but will get your things rolling.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Why not just 'format' it twice, inline the two calls? Seems like that would work...
-craig

"You can never have too many knives" -- Logan Nine Fingers
JezT
Participant
Posts: 75
Joined: Wed Sep 15, 2004 1:52 am

Post by JezT »

I have used the following:

Code: Select all

Field(ResultsWrite2.LGD_CALC_VAL, ".", 1, 1)
and

Code: Select all

Field(ResultsWrite2.LGD_CALC_VAL, ".", 2, 1)
And for a value of 79.12 this gives me two values : 79 and 12.

When I then do

Code: Select all

Fmt(LGDFirst, "R'0'4")
where LGD is the StageVariable name for the first bit of code above, I get the following output :

'''''
And I was hoping to see 0079
Any ideas ?
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

the fmt code is

Code: Select all

Fmt(LGDFirst, "4'0'R")
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Code: Select all

Fmt(Fmt(ResultsWrite2.LGD_CALC_VAL,"7'0'R"),"9'0'L")
-craig

"You can never have too many knives" -- Logan Nine Fingers
kumar_s
Charter Member
Charter Member
Posts: 5245
Joined: Thu Jun 16, 2005 11:00 pm

Post by kumar_s »

Hi,
Is it not possible to read those numbers as decimal so that N.N will be automatically converted to NNNN.NNNN or whatever??
Impossible doesn't mean 'it is not possible' actually means... 'NOBODY HAS DONE IT SO FAR'
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

No. Remember the 'Server is typeless' mantra. And that the zeroes are not significant. So you need to explicitly 'format' them into a character field in order to preserve them.
-craig

"You can never have too many knives" -- Logan Nine Fingers
Post Reply