English

How To: Format AML numeric strings with commas

Procedure

How can a numeric string, contained in a variable, be formatted to use commas to delimit digits in values greater that 999? For example, can the string 100000 be shown as 100,000?

Answer:

This can be accomplished by parsing the necessary string length and inserting
commas. The following AML inserts commas every three digits:

/* numcomma.aml
/*
&ARGS X
&SETVAR NEW
&DO &WHILE %x% >= 1000
&SETVAR temp = [SUBSTR %x% [CALC [LENGTH %x%] - 2] [LENGTH %x%]]
&SETVAR new = ,%temp%%new%
&SETVAR x = [SUBSTR %x% 1 [CALC [LENGTH %x%] - 3]]
&END
&IF [NULL %new%] &THEN &SETVAR new = %x%
&ELSE &SETVAR new = %x%%new%
&TYPE NEW IS %new%
&SETVAR .return = %new%
&RETURN