AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   check if number is float (https://forums.alliedmods.net/showthread.php?t=246153)

IAmReallyCool 08-12-2014 16:50

check if number is float
 
Is there any native to check if the number is float ?
Like this :

if(is_float(number))
this is float

fysiks 08-12-2014 16:56

Re: check if number is float
 
Variable must be specifically defined as a float so you already know if a number is a floating point number.

claudiuhks 08-13-2014 01:20

Re: check if number is float
 
Quote:

Originally Posted by IAmReallyCool (Post 2183084)
Is there any native to check if the number is float ?
Like this :

if(is_float(number))
this is float

If number variable is a string, check it using the way below.

PHP Code:

if (contain(number".") != -1)
{
  
// might be float


Note that if the number is 1.000000 then it might also be an integral value (1).
So if you read our messages you will definitely understand.

HamletEagle 08-13-2014 04:12

Re: check if number is float
 
Quote:

Originally Posted by claudiuhks (Post 2183251)
If number variable is a string, check it using the way below.

PHP Code:

if (contain(number".") != -1)
{
  
// might be float


Note that if the number is 1.000000 then it might also be an integral value (1).
So if you read our messages you will definitely understand.

And what if he checks a string like Test.Test1 ?

Backstabnoob 08-13-2014 05:10

Re: check if number is float
 
Quote:

Originally Posted by claudiuhks (Post 2183251)
If number variable is a string, check it using the way below.

PHP Code:

if (contain(number".") != -1)
{
  
// might be float


Note that if the number is 1.000000 then it might also be an integral value (1).
So if you read our messages you will definitely understand.

is_str_float?

fysiks 08-13-2014 12:05

Re: check if number is float
 
Quote:

Originally Posted by Backstabnoob (Post 2183304)
is_str_float?

If it existed, it might be relevant :).

Backstabnoob 08-13-2014 12:12

Re: check if number is float
 
That's strange, I'm almost sure it existed o.O

Well, this is still better (by Exolent) than a contain check:

PHP Code:

stock bool:is_str_float(const string[])
{
    new 
cip;
    while(
is_char(string[i++]))
    {
        if(!
isdigit(c))
        {
            if(
!= '.' || p)
            {
                return 
false;
            }
            
            
1;
        }
    }
    
    return (
1);



HamletEagle 08-13-2014 12:14

Re: check if number is float
 
https://forums.alliedmods.net/showthread.php?t=163205
It exists.

fysiks 08-13-2014 12:15

Re: check if number is float
 
I think we have an XY Problem going on here. OP, please explain what you are actually trying to achieve here. There might even be a simpler solution or one completely different.

Quote:

Originally Posted by Backstabnoob (Post 2183510)
That's strange, I'm almost sure it existed o.o

Me too but proved myself otherwise.

IAmReallyCool 08-14-2014 03:32

Re: check if number is float
 
I have got admin cmd to give player invisibility for seconds..

Seconds are defined like this (not float)

new secs

I am aware that admins can type something like this

give_invis STEAM_HERE 1.4

I want to allow only round numbers...


All times are GMT -4. The time now is 13:14.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.