Problem about convert decimal to string

Posted by Admin on 29-Apr-2009 01:11

Guys, I met a problem when I try to convert a decimal to string using string() function. When it is less than 1, for example 0.5, the zero before the point is always cut, means the result is .5. Following is my code. Anyone can help me? Thanks in advance!!

DISPLAY STRING( 50 / 100 ).

All Replies

Posted by jmls on 29-Apr-2009 01:30

try using the format option

display string(50 / 100,">>9.99")

Posted by Admin on 29-Apr-2009 01:56

Hello Julian Lyndon, thanks for your attention. but if so the integer part and decimal digits will be fixed on 3 digits and 2 digits. In fact both of them are alterable. So I want to keep the result unchanged (not formatted). The original code in my procedure is as following:

DEF INPUT PARAM pBarcode AS CHARACTER.
DEF OUTPUT PARAM strThk AS CHARACTER.
FIND rt_barcode NO-LOCK WHERE rt_barcode.barcode=pBarcode.
strThk = string( rt_barcode.thickness / 100).

Any idea?

Thanks again.

Posted by Admin on 29-Apr-2009 02:08

Is there anything you can tell about the expected result? What data-type is rt_barcode.thickness?

If nothing else will help, add the 0 to the resulting string, like this:

DEFINE VARIABLE deResult AS DECIMAL     NO-UNDO.

DEFINE VARIABLE cResult AS CHARACTER   NO-UNDO.

deResult = 42 / 100 .

cResult = STRING(deResult) .

IF deResult = 0 THEN

    cResult = "0" + cResult .

MESSAGE cResult.

Posted by Admin on 29-Apr-2009 02:11

Actually, I guess my code needs some more tuning if you're expecting values between 0 and -1 as well.

Posted by jmls on 29-Apr-2009 02:12

so, you want

a) the leading 0 shown if the amount

b) a variable number of significant and non-significant digits

Right!.

display trim(string(50 / 100,">>>>>>>>>9.9<<<<<

or

display trim(trim(string(50 / 10,">>>>>>>>>9.9<<<<<

added case where result is integer

Posted by Admin on 29-Apr-2009 02:33

Hi Mike, rt_barcode. thickness is a deciamal type. Thank you so much too Actually this is the exact way I don't want to take, but at this point I have to do it this way I guess. Because it seemes there isn't a function can do this convertion directly in Progress 4GL. That is the reason why I request help here. Anyway, thank all you guys share your experience with me. very happy with my first discussion here. Wish we can learn from each other more and more in future.

Posted by Admin on 29-Apr-2009 02:46

Hi Julian Lyndon, you are great, that is what i wanted. Thanks a lot!

Posted by jmls on 29-Apr-2009 03:42

No problem. Glad to be of help.

This thread is closed