Number format

24 views
Skip to first unread message

Jean-Louis Tourné

unread,
Jan 18, 2023, 5:21:55 AMJan 18
to
Hello,

How can I display (SAY) the number 123456789 under the form 123.456.789 ?

Thank you

Jaime Cruz

unread,
Jan 18, 2023, 8:27:29 AMJan 18
to
/******************************* REXX *********************************/
/* REXX External Function written by Gerard Schildberger and */
/* uploaded to the comp.lang.rexx Usenet newsgroup on June 11, */
/* 2007 in response to a question from me. */
/* */
/* Arguments are: */
/* Comma(_, c, s, t) */
/* Where: */
/* _ = the input number to have commas inserted */
/* c = Character to be inserted (Default = ',') */
/* n = Number of spaces between "c" */
/* t = total insertions to perform (Default = 9999999) */
/**********************************************************************/
Parse Arg _, c, s, t

c = PickBlank(c, ',')
If \IsInt(s) | ,
s < 1 Then
s = 3

n = _ || '.9'
a = 123456789
k = 0
If \IsInt(t) Then
t = 9999999

Do j = Verify(n, a || '0', , Verify(n, a || '0.', 'M')) - s - 1 To ,
Verify(n, a, 'M') By -s While k < t
_ = Insert(c, _, j)
k = k + 1
End

Exit _

/**********************************************************************/
/* Subroutine to determine if a number is a whole number or not. */
/**********************************************************************/
IsInt:
Procedure
Return Datatype(Arg(1), 'W')

/**********************************************************************/
/* Subroutine to select the insertion character or blanks. */
/**********************************************************************/
PickBlank:
Procedure
Parse Arg x, y
Arg xu
If xu == 'BLANK' Then
Return ' '
Return Word(x y, 1)

--
Jaime A. Cruz

Nassau Wings Motorcycle Club
http://www.nassauwings.org/


Jean-Louis Tourné

unread,
Jan 18, 2023, 12:21:21 PMJan 18
to
Thank You for this quick response. I imagined that there was maybe a rexx " FORMAT" instruction to obtain the same result.

Gil Barmwater

unread,
Jan 18, 2023, 2:08:55 PMJan 18
to
Here is another way to do it if you are using ooRexx. Note that it
assumes the input string is an integer but allows for the character to
be inserted (.) to be changed as well as the length of each sub-string (3).

if arg() > 0 then do
use arg a.1, a.2='.', a.3=3
return chunk(a.1, a.2, a.3)
end

::routine chunk public
use arg str, sep=',', size=3
if str~length > size then do
parse value str~length-size'|'str with p '|' +1 front +(p) back
str = chunk(front, sep, size)||sep||back
end
return str

--
Gil Barmwater

ErichSt

unread,
Jan 19, 2023, 4:41:02 AMJan 19
to
> How can I display (SAY) the number 123456789 under the form 123.456.789 ?
say translate('abc.def.ghi', 123456789, 'abcdefghi')

For the general case, covering also smaller numbers, you could use
say strip(translate('abc.def.ghi', 12345~right(9), 'abcdefghi'), 'l', ' .')

Jean-Louis Tourné

unread,
Jan 19, 2023, 6:57:31 AMJan 19
to
Thank You all
Reply all
Reply to author
Forward
0 new messages