Difference between revisions of "NumberFormat"

From Second Life Wiki
Jump to navigation Jump to search
m (LlNumberFormat moved to NumberFormat: LSL pages prefixed with LL are reserved for feature suggestions and official functions.)
m (<lsl> tag to <source>)
 
(2 intermediate revisions by one other user not shown)
Line 1: Line 1:
{{LSL Header}}
{{LSL Header}}


=== ''string'' '''llNumberFormat'''(''integer'') ===
=== ''string'' '''NumberFormat'''(''integer'') ===
You can use this to take large numbers and format them to be comma separated by thousands.
You can use this to take large numbers and format them to be comma separated by thousands.
<lsl>
<source lang="lsl2">
string llNumberFormat(integer number)
string NumberFormat(integer number)
{
{
     string output;     
     string output;     
Line 21: Line 21:
     return output;
     return output;
}
}
</lsl>
</source>


{{LSLC|Examples}}
{{LSLC|Examples}}
{{#vardefine:sort|llNumberFormat}}
{{#vardefine:sort|NumberFormat}}

Latest revision as of 16:32, 24 January 2015

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