Number Formatting

Getting into LiveCode for iOS? Ask your questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
dburdan
Posts: 104
Joined: Fri Jan 28, 2011 5:39 am
Location: California, USA

Number Formatting

Post by dburdan » Tue Feb 22, 2011 2:40 am

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"?

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am
Location: Bordeaux, France

Re: Number Formatting

Post by Dixie » Tue Feb 22, 2011 11:04 am

hi...

Look at the attached stack... it might help

be well

Dixie
Attachments
commaNumbers.rev.zip
(1.27 KiB) Downloaded 262 times

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am
Location: Bordeaux, France

Re: Number Formatting

Post by Dixie » Tue Feb 22, 2011 11:26 am

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

dburdan
Posts: 104
Joined: Fri Jan 28, 2011 5:39 am
Location: California, USA

Re: Number Formatting

Post by dburdan » Tue Feb 22, 2011 5:55 pm

Thanks that should work!

Post Reply

Return to “iOS Deployment”