Difference between revisions of "NumberFormat"

From Second Life Wiki
Jump to navigation Jump to search
m (Added to LSL Library and Examples)
(Add tags to show entry in TOC)
Line 1: Line 1:
{{LSL Header}}
=== ''string'' '''llNumberFormat'''(''integer'') ===
=== ''string'' '''llNumberFormat'''(''integer'') ===
You can use this to take large numbers and format it to be comma seperated by thousands.
You can use this to take large numbers and format it to be comma seperated by thousands.
Line 22: Line 24:


{{LSLC|Library}}{{LSLC|Examples}}
{{LSLC|Library}}{{LSLC|Examples}}
{{#vardefine:sort|Hello Avatar}}

Revision as of 03:43, 7 September 2007

string llNumberFormat(integer)

You can use this to take large numbers and format it to be comma seperated by thousands.

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;
}