Difference between revisions of "NumberFormat"
Jump to navigation
Jump to search
Fox Diller (talk | contribs) m (Added to LSL Library and Examples) |
m (<lsl> tag to <source>) |
||
(9 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
=== ''string'' ''' | {{LSL Header}} | ||
You can use this to take large numbers and format | |||
< | === ''string'' '''NumberFormat'''(''integer'') === | ||
string | You can use this to take large numbers and format them to be comma separated by thousands. | ||
<source lang="lsl2"> | |||
string NumberFormat(integer number) | |||
{ | { | ||
string output; | string output; | ||
Line 19: | Line 21: | ||
return output; | return output; | ||
} | } | ||
</ | </source> | ||
{{LSLC| | {{LSLC|Examples}} | ||
{{#vardefine:sort|NumberFormat}} |
Latest revision as of 16:32, 24 January 2015
LSL Portal | Functions | Events | Types | Operators | Constants | Flow Control | Script Library | Categorized Library | Tutorials |
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;
}