IsNumeric - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: IsNumeric (
/showthread.php?tid=639467)
IsNumeric -
IchNar - 18.08.2017
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 i = 0, j = strlen(string); i < j; i++)
{
if (string[i] > '9' || string[i] < '0') return 0;
}
return 1;
}
Re: IsNumeric -
Kane - 18.08.2017
Are you asking how to check if a
FLOAT is numeric?
Re: IsNumeric -
Tibbzz - 18.08.2017
Where do i put that
code in?
Re: IsNumeric -
IchNar - 18.08.2017
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.
Re: IsNumeric -
Toroi - 18.08.2017
Код:
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.
Re: IsNumeric -
Kane - 18.08.2017
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 i = 0, j = 0; i < strlen(params); i++)
{
index[j] = i;
j++;
}
for(new i = 0; i < sizeof(index); i++)
{
if(params[index[i] + 1] == '.')
{
foundFloat = true;
}
}
if(foundFloat)
{
SendClientMessage(playerid, -1, "A possible float was found, the results:");
format(str, sizeof(str), "%s", params);
SendClientMessage(playerid, -1, str);
}
else
{
SendClientMessage(playerid, -1, "A possible float was not found, the results:");
format(str, sizeof(str), "%s", params);
SendClientMessage(playerid, -1, str);
}
Re: IsNumeric -
IchNar - 18.08.2017
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...
Re: IsNumeric -
Vince - 18.08.2017
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.
Re: IsNumeric -
DimaShift - 19.08.2017
https://sampwiki.blast.hk/wiki/Strval