NumberFormat: Difference between revisions
Jump to navigation
Jump to search
Strange function but i couldn't resist doing a small optimization (equivalent but faster) |
Fox Diller (talk | contribs) m Added to LSL Library and Examples |
||
| Line 1: | Line 1: | ||
=== ''string'' '''llNumberFormat'''(''integer'') === | === ''string'' '''llNumberFormat'''(''integer'') === | ||
You can use this to take large numbers and format it to be comma seperated by thousands. | |||
<pre> | <pre> | ||
string llNumberFormat(integer number) | string llNumberFormat(integer number) | ||
| Line 19: | Line 20: | ||
} | } | ||
</pre> | </pre> | ||
{{LSLC|Library}}{{LSLC|Examples}} | |||
Revision as of 22:16, 23 May 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;
}