Raised This Month: $ Target: $400
 0% 

check if number is float


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
IAmReallyCool
Member
Join Date: Nov 2013
Old 08-12-2014 , 16:50   check if number is float
Reply With Quote #1

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

if(is_float(number))
this is float
IAmReallyCool is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 08-12-2014 , 16:56   Re: check if number is float
Reply With Quote #2

Variable must be specifically defined as a float so you already know if a number is a floating point number.
__________________
fysiks is offline
claudiuhks
Yam Inside®™℠
Join Date: Jan 2010
Location: Living Randomly
Old 08-13-2014 , 01:20   Re: check if number is float
Reply With Quote #3

Quote:
Originally Posted by IAmReallyCool View Post
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.
__________________

Last edited by claudiuhks; 08-13-2014 at 01:20.
claudiuhks is offline
Send a message via MSN to claudiuhks Send a message via Yahoo to claudiuhks Send a message via Skype™ to claudiuhks
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 08-13-2014 , 04:12   Re: check if number is float
Reply With Quote #4

Quote:
Originally Posted by claudiuhks View Post
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 ?
__________________
HamletEagle is offline
claudiuhks
Yam Inside®™℠
Join Date: Jan 2010
Location: Living Randomly
Old 08-17-2014 , 18:13   Re: check if number is float
Reply With Quote #5

Quote:
Originally Posted by HamletEagle View Post
And what if he checks a string like Test.Test1 ?
I didn't mean random strings.
__________________
claudiuhks is offline
Send a message via MSN to claudiuhks Send a message via Yahoo to claudiuhks Send a message via Skype™ to claudiuhks
Backstabnoob
BANNED
Join Date: Feb 2009
Location: Iwotadai Dorm
Old 08-13-2014 , 05:10   Re: check if number is float
Reply With Quote #6

Quote:
Originally Posted by claudiuhks View Post
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?
Backstabnoob is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 08-13-2014 , 12:05   Re: check if number is float
Reply With Quote #7

Quote:
Originally Posted by Backstabnoob View Post
is_str_float?
If it existed, it might be relevant .
__________________
fysiks is offline
Backstabnoob
BANNED
Join Date: Feb 2009
Location: Iwotadai Dorm
Old 08-13-2014 , 12:12   Re: check if number is float
Reply With Quote #8

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


Last edited by Backstabnoob; 08-13-2014 at 12:13.
Backstabnoob is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 08-13-2014 , 12:15   Re: check if number is float
Reply With Quote #9

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 View Post
That's strange, I'm almost sure it existed o.o
Me too but proved myself otherwise.
__________________
fysiks is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 08-13-2014 , 12:14   Re: check if number is float
Reply With Quote #10

https://forums.alliedmods.net/showthread.php?t=163205
It exists.
__________________

Last edited by HamletEagle; 08-13-2014 at 12:14. Reason: BackStab was faster.
HamletEagle is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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