NumberFormat

From Second Life Wiki
Revision as of 17:32, 24 January 2015 by ObviousAltIsObvious Resident (talk | contribs) (<lsl> tag to <source>)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

string NumberFormat(integer)

You can use this to take large numbers and format them to be comma separated by thousands.

string NumberFormat(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;
}