Wilson WindowWare Tech Support

WinBatch WinBatch+Compiler WebBatch
Home | Tech Database | Tech BBS | White Papers | Purchase


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