Page 1 of 1

DecimalToSting()

Posted: Thu Jan 03, 2008 10:21 am
by vrishabhsagar
Hi All,

I have a source file col that has decimal data in form 020, but when I convert it into varchar format using DecimalToString(colname), then it is automatically converted to something like 20. I would like output in form 020 (varchar data).

Can anyone pls help.

Thanks in anticipation.

Rishabh

Posted: Thu Jan 03, 2008 10:43 am
by dspxlearn
Did you try using 'Fix_xero" with the DecimalToString function?
If not please check this.

Else you can do the formatting stuff:

Code: Select all

Right( Str('0',n) : DecimalToString(InCol,"fix_zero"), n)
Please let us know your results

Re: DecimalToSting()

Posted: Thu Jan 03, 2008 11:26 am
by ArndW
vrishabhsagar wrote:...I have a source file col that has decimal data in form 020...
Decimal data is not stored with leading zeroes; that is a function of how you display it. The string formatting function that
dspxlearn suggested should work for you when reconverting the number back to a string.

Have used this

Posted: Thu Jan 03, 2008 11:47 am
by vrishabhsagar
Hi All,

Thanks for responding... Right now I have used this to fix the problem,

Str("0",3-len(trim(DecimalToString(DSLink3.FLQ66B080_TOACDE1,"suppress_zero")))):DecimalToString(DSLink3.FLQ66B080_TOACDE1,"suppress_zero")

Since I am running out of time, I am unable to test ur solution. But when I test it, if I find any thing of interest I shall definetly bump this thread or PM.

Thanks Again.

Posted: Thu Jan 03, 2008 3:28 pm
by dspxlearn
vrishabhsagar,
You don't need to test the code which i have posted previously. Cause, it will do the same thing as yours.Only difference, is that you are taking the exact length of the prefixed Zeros.
If your issue is solved please mark it as 'Resolved'.

Posted: Thu Jan 03, 2008 3:56 pm
by ray.wurlod
The answer is NO.
A Decimal number is a binary data type. Whether it has leading zeroes or not it is stored the same way. DecimalToString() generates the shortest possible valid string.
If you want to add leading zeroes, then you must do so explicitly. For example:

Code: Select all

Right("000" : DecimalToString(InLink.TheDecimal), 3)