IsNumeric
#1

Greedings,i want to ask you something.I have got stock IsNumeric from the net,and i want to isnumeric with float numbers.
Code:
PHP код:
stock IsNumeric(const string[])
{
    for (new 
0strlen(string); ji++)
    {
        if (
string[i] > '9' || string[i] < '0') return 0;
    }
    return 
1;

Reply
#2

Are you asking how to check if a FLOAT is numeric?
Reply
#3

Where do i put that
code in?
Reply
#4

I want to check this,if this string is number or if its float number.For example he can write 9 but he can write also 9.2.
Reply
#5

Код:
stock IsNumeric(const string[]) 
{ 
    new possiblefloat = 0;
    for (new i = 0, j = strlen(string); i < j; i++) 
    { 
        if (string[i] > '9' || string[i] < '0')
        {
            if(string[i] != '.')
                return 0;
            else
                possiblefloat = 1;
        }
    }
    if(possiblefloat == 1)
        return 2;
    else
        return 1; 
}
will return 2 if float 1 if integer. it works in my brain.
Reply
#6

I'm going to post this anyway because I spent some time making and testing it which I'm no good at.



PHP код:
    new bool:foundFloat false;
    new 
str[128], index[128];
    
    if(!
IsNumeric(params))
        return 
SendClientMessage(playerid, -1"Your input does not have any numbers."); 
        
    for(new 
00strlen(params); i++)
    {
        
index[j] = i
        
j++;
    }
    
    for(new 
0sizeof(index); i++)
    {
        if(
params[index[i] + 1] == '.')
        {
            
foundFloat true;
        }
    }
    
    if(
foundFloat)
    {
        
SendClientMessage(playerid, -1"A possible float was found, the results:");
        
        
format(strsizeof(str), "%s"params);
        
SendClientMessage(playerid, -1str);
    }
    else
    {
        
SendClientMessage(playerid, -1"A possible float was not found, the results:");
        
        
format(strsizeof(str), "%s"params);
        
SendClientMessage(playerid, -1str);
    } 
Reply
#7

Toroi its work!! Thank you,but i have got one more ask how to check if player write dot first for example .2,.2.2...
Reply
#8

Large functions, all for nothing.
PHP код:
bool:IsNumeric(const string[])
    return !
sscanf(string"{f}"); 
Although IsNumeric is usually redundant because in most cases you will want to get the value from the string anyway. In which case it is much better to use sscanf directly.
Reply
#9

https://sampwiki.blast.hk/wiki/Strval
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)