Don't click here unless you want to be banned.

LSL Wiki : ExampleIsValidFloatFormat

HomePage :: PageIndex :: RecentChanges :: RecentlyCommented :: UserSettings :: You are crawl338.us.archive.org
Check wether a string contains a properly formatted Float value.

string DIGITS="0123456789";

integer IsValidFloatFormat(string rawvalue)
{
    string  value=llStringTrim(rawvalue,STRING_TRIM);
    integer len=llStringLength(value);
    integer ndigits=0;
    integer nperiods=0;
    string  char=llGetSubString(value,0,0);
    integer i=0;
    
    // Skip leading sign
    if (char == "+" || char== "-")
        ++i;
        
    for(; i < len; ++i)
    {
        char=llGetubString(value,i,i);
        if (llSubStringIndex(DIGITS,char) != -1)
        {
            ++ndigits;
        }
        else if (char == ".")
        {
            if (++nperiods > 1)
                return FALSE;
        }
        else
        {
            return FALSE;
        }
    }
    
    // A float consists of minimal 1 digit and must have a period
    if (ndigits < 1 || nperiods != 1)
        return FALSE;
        
    return TRUE;
}



Examples
There is no comment on this page. [Display comments/form]