Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Number format

32 views
Skip to first unread message

Jean-Louis Tourné

unread,
Jan 18, 2023, 5:21:55 AM1/18/23
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 AM1/18/23
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 PM1/18/23
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 PM1/18/23
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 AM1/19/23
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 AM1/19/23
to
Thank You all
0 new messages