Page 1 of 1

Number Formatting

Posted: Tue Feb 22, 2011 2:40 am
by dburdan
I have a variable "score" that holds the users score value. This number can often reach more than 1 million. Is there any way to format it like "11,000,000" instead of "11000000"?

Re: Number Formatting

Posted: Tue Feb 22, 2011 11:04 am
by Dixie
hi...

Look at the attached stack... it might help

be well

Dixie

Re: Number Formatting

Posted: Tue Feb 22, 2011 11:26 am
by Dixie
hi...

or in a function...

Code: Select all

on mouseUp
   put commaNumber(fld 1) into fld 1
end mouseUp

function commaNumber theString
   put the number of chars of theString into charCount
   if charCount < 3 then exit commaNumber
   
   put 0 into commaCount
   repeat with count = charCount down to 1
      
      if commaCount = 3 then
         put comma before commaNumbers
         put 0 into commaCount
      end if
      
      put char count of theString before commaNumbers
      add 1 to commaCount
   end repeat
   
   return commaNumbers
end commaNumber
I should have posted that first...

Dixie

Re: Number Formatting

Posted: Tue Feb 22, 2011 5:55 pm
by dburdan
Thanks that should work!