decimal to string

goslows

New Member
Does anyone have the answer to change the format of a decimal to a string with leading zeros and cents showing? Example: I wish to display 120.25 in 10 spaces to look like 0000012025. Any help would be much appreciated!
 
def var v-dec as dec.
v-dec = 120.25.
disp string(v-dec,'99999999.99') format 'x(11)'.

Should do the trick.
Note that this is going to display 00000120.25 with a decimal. You can leave out the decimal in the formatting, but then it will round to 0000000120 - you're call on that one.

Mark



goslows said:
Does anyone have the answer to change the format of a decimal to a string with leading zeros and cents showing? Example: I wish to display 120.25 in 10 spaces to look like 0000012025. Any help would be much appreciated!
 
Try this

Code:
DEFINE VARIABLE f$dec AS DECIMAL NO-UNDO.
DEFINE VARIABLE i$dec AS INTEGER NO-UNDO.

ASSIGN f$dec = 120.25
       i$dec = f$dec * 100.
       
DISP STRING(i$dec,"9999999999") FORMAT "X(10)".
goslows said:
Does anyone have the answer to change the format of a decimal to a string with leading zeros and cents showing? Example: I wish to display 120.25 in 10 spaces to look like 0000012025. Any help would be much appreciated!
 
Yep, it occurred to me in the wee hours of the morning (who knows why I was thinking about THIS at 3am) that the desired result could be accomplished by first multiplying by 100.
Though I would have done it with just one variable. (Which is NOT to say that would be better, just different. I'm sure there are nearly as many was to do something as there are programmers to do it.)
I'm thinking
disp string((v-dec * 100),'999999999') format "x(10)"
would work equally well.

So now he has choices (and ain't that grand).


bendaluz2 said:
Try this

Code:
DEFINE VARIABLE f$dec AS DECIMAL NO-UNDO.
DEFINE VARIABLE i$dec AS INTEGER NO-UNDO.

ASSIGN f$dec = 120.25
       i$dec = f$dec * 100.
       
DISP STRING(i$dec,"9999999999") FORMAT "X(10)".
 
Back
Top