Difference between revisions of "NumberFormat"

From Second Life Wiki
Jump to navigation Jump to search
m (typo)
m (grammar)
Line 2: Line 2:


=== ''string'' '''llNumberFormat'''(''integer'') ===
=== ''string'' '''llNumberFormat'''(''integer'') ===
You can use this to take large numbers and format it to be comma separated by thousands.
You can use this to take large numbers and format them to be comma separated by thousands.
<lsl>
<lsl>
string llNumberFormat(integer number)
string llNumberFormat(integer number)

Revision as of 15:06, 30 March 2008

string llNumberFormat(integer)

You can use this to take large numbers and format them to be comma separated by thousands. <lsl> string llNumberFormat(integer number) {

   string output;    
   integer x = 0;
   string numberString = (string)number;
   integer numberStringLength = llStringLength(numberString);
   integer z = (numberStringLength + 2) % 3;
   
   for(;x < numberStringLength; ++x)
   {
       output += llGetSubString(numberString, x, x);
       if ((x % 3) == z && x != (numberStringLength - 1))
           output += ",";
   }
   
   return output;

} </lsl>