Skip to content

Instantly share code, notes, and snippets.

@lbdyck
Last active December 9, 2022 14:50
Show Gist options
  • Save lbdyck/bdda84f144e2a50bb98ac9c62b19ac12 to your computer and use it in GitHub Desktop.
Save lbdyck/bdda84f144e2a50bb98ac9c62b19ac12 to your computer and use it in GitHub Desktop.
REXX subroutine to Convert a number to a string with commas (e.g. 1000000 becomes 1,000,000)
/* ----------------- REXX ------------------------- *
| Take a number and display it with comma's in it. |
| |
| e.g. 1000 becomes 1,000 |
| |
| usage: comma_num = addcomma(number) |
| |
| supports numbers up to 34 digits long |
| |
| Copied from Doug Nadel |
* ------------------------------------------------ */
AddComma: Procedure /* for numbers > 16 digits */
arg bignum
cbignum = strip(translate('0,123,456,789,abc,def,ghi,jkl,mno,pqr,stu,vwx', ,
right(bignum,34,','), ,
'0123456789abcdefghijklmnopqrstuvwx'),'L',',')
return cbignum
/* A more compact version */
AddComma: Procedure /* for numbers up to 16 digits */
arg bytes
/* ----------------------------------------------------- */
/* number format code thanks to Doug Nadel */
/* ----------------------------------------------------- */
str=strip(translate('0,123,456,789,abc,def', ,
right(bytes,16,','), ,
'0123456789abcdef'),'L',',')
bytes = strip(str)
return bytes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment