I was wondering if there was a simplistic code to add commas as thousands separators in variables that takes into account the length of the digit. For example, if The variable equals 123576
I would want it to become 123,456
, but if the variable were equal to 1234567
then I would want it to turn into 1,234,567
.
CodePudding user response:
ECHO Processing %num%
SET "withcommas="
:subl
IF DEFINED num SET "withcommas=%num:~-3%,%withcommas%"&SET "num=%num:~0,-3%"&GOTO subl
SET "withcommas=%withcommas:~0,-1%"
ECHO result=%withcommas%
Processes num
to required format. Note : num
will be undefined by code.