WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Number Conversion

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

How to Add Commas to Numbers to Make them More Readable

Keywords: 	  format numbers

;Original number to format
orignum=1234567890

;formatted number
fmtnum=orignum

;only format integers
if orignum<2140000000
   ;clear out formatted version
   fmtnum=""

   ;set temporary variable
   a=orignum

   ; do till done
   while @TRUE
      ;get remaining length
      alen=strlen(a)
      ;compute how many to grab
      top=( (alen+2) mod 3) + 1
      ;grab upper part
      atop=strsub(a,1,top);
      ;save lower part
      a=strsub(a,top+1,-1)
      ;glue number together
      if fmtnum=="" then fmtnum=atop
      else fmtnum=strcat(fmtnum,",",atop)
      ;done yet?
      if a=="" then break
   endwhile

;Display numbers
Message(orignum,fmtnum)


Article ID:   W14226
Filename:   Add Commas to Numbers to Make Readable.txt
File Created: 1999:10:26:11:22:36
Last Updated: 1999:10:26:11:22:36