snippet - Limit floats numbers and vectors to 2 digits.

Two little LSL functions to limit floats to only 2 digits.



string float2Str(float in)
{
    return (string)((integer)in) + "." + (string)((integer)((in - (integer)in) * 100));
}

string vector2Str(vector v) 
{
    return "<" + float2Str(v.x) + ", " + float2Str(v.y) + ", " + float2Str(v.z) + ">";
}

default
{
    state_entry()
    {
    }

    touch_start(integer total_number)
    {
        vector v = <215.7509, 235.845750, 4001.50356>;
        
        llOwnerSay((string) v + "  =======  " + vector2Str(v));
    }
}


If you wants less or more decimals you must modify the float2Str function and change the 100 by 10 if you want only 1 decimal or 1000, 10000, etc if you want more decimals.


Comments

Popular posts from this blog

Linksets in SecondLife (2)

Linksets in SecondLife (1)

About the death and rebirth of my auto greeter