Difference between revisions of "ListToWholeNumbers"

From Second Life Wiki
Jump to navigation Jump to search
m
m (<lsl> tag to <source>)
 
Line 9: Line 9:
See also: [[List|Lists]]
See also: [[List|Lists]]
|examples=
|examples=
<lsl>list myWholeNumberList = ListToWholeNumbers( [1.04, 10.789, 4.643] );//yields [1,10,4]</lsl>
<source lang="lsl2">list myWholeNumberList = ListToWholeNumbers( [1.04, 10.789, 4.643] );//yields [1,10,4]</source>
|spec=<lsl>list ListToWholeNumbers(list myList)
|spec=<source lang="lsl2">list ListToWholeNumbers(list myList)
{
{
     integer ListLength = llGetListLength(myList);
     integer ListLength = llGetListLength(myList);
Line 25: Line 25:
     }
     }
     return myList;
     return myList;
}</lsl>
}</source>
|helpers
|helpers
|also_functions
|also_functions

Latest revision as of 14:22, 22 January 2015

Summary

Function: list ListToWholeNumbers( list mylist );

Takes a list and truncates each float in the list so that it is a whole number.
Returns a list that contains the elements of myList but with the float elements having their fractional parts removed.

• list mylist

See also: Lists

Specification

list ListToWholeNumbers(list myList)
{
    integer ListLength = llGetListLength(myList);
    integer i = -1;
    while (++i < ListLength)
    {
        if(TYPE_FLOAT == llGetListEntryType(myList, i))
        {
            float f = llList2Float(myList, i);
            if(llFabs(f) < 0x1000000)//can it have an fpart?
                f = (integer)f;
            myList = (myList = []) + llListReplaceList(myList, (list)f, i, i);
        }
    }
    return myList;
}

Examples

list myWholeNumberList = ListToWholeNumbers( [1.04, 10.789, 4.643] );//yields [1,10,4]