#1

Hi,

1. How to check is string is float?
2. How to check how much numbers is after .? if number like this

523.522288881

Then output 9. Because i want to do that player can't to write long floats like that: 1.0025498989..
Reply
#2

1. You can use floatstr(); to convert a string to a float.
Reply
#3

pawn Код:
new
    dot_pos = strfind(string, "."),
    count;
       
if(dot_pos != -1)
    count = strlen(string) - dot_pos - 1;
Also, use floatstr.
Reply
#4

i dont know if i got it right but try this :
pawn Код:
new Str[64];
new Float:x, Float:y, Float:z;
GetPlayerPos(playerid, x, y, z);
format(Str, sizeof(Str), "%.2f, %.2f, %.2f", x, y, z);
SendClientMessage(playerid, 0xFFFF00FF, Str);
Reply
#5

2.
pawn Код:
new str[16] = "523.522288881", point, decimals;
point = strfind(str, ".", false);
for(new i=(point+1); i<strlen(str); i++)
{
    if(str[i] != EOS)
    {
        decimals++;
    }
}
if(decimals > 2)
{
    SendClientMessage(playerid, 0xFF0000AA, "You are not allowed to enter more than 2 decimals");
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)