SA-MP Forums Archive
Float - 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: Float (/showthread.php?tid=550061)



Float - Banditukas - 10.12.2014

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..


Re: Float - Schneider - 10.12.2014

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


Re: Float - fordawinzz - 10.12.2014

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


Re: Float - UltraScripter - 10.12.2014

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);



Re: Float - Schneider - 10.12.2014

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");
}