Page 1 of 1

Number Formatting

Posted: Fri May 19, 2006 5:24 am
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 ?

Posted: Fri May 19, 2006 6:23 am
by kumar_s
You are talking about the data type Decimal and Integer for you two cases in the order.

Posted: Fri May 19, 2006 6:26 am
by sb_akarmarkar
Use field and Concatenation

Thanks,
Anupam

Posted: Fri May 19, 2006 6:29 am
by kumar_s
Decimal has first bit as sign bit.

Posted: Fri May 19, 2006 6:46 am
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.

Posted: Fri May 19, 2006 6:47 am
by chulett
Forgot to mention that 'FMT' will handle both of your examples: the zero padding and the 'descaling' of the decimal point.

Posted: Fri May 19, 2006 8:22 am
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.

Posted: Fri May 19, 2006 8:24 am
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.

Posted: Fri May 19, 2006 8:27 am
by chulett
Why not just 'format' it twice, inline the two calls? Seems like that would work...

Posted: Fri May 19, 2006 8:59 am
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 ?

Posted: Fri May 19, 2006 9:33 am
by DSguru2B
the fmt code is

Code: Select all

Fmt(LGDFirst, "4'0'R")

Posted: Fri May 19, 2006 10:04 am
by chulett

Code: Select all

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

Posted: Sat May 20, 2006 5:07 am
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??

Posted: Sat May 20, 2006 6:37 am
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.