Raised This Month: $ Target: $400
 0% 

check if number is float


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 08-14-2014 , 15:18   Re: check if number is float
Reply With Quote #1

You never need to check if it's a float, you simply need to truncate it which is automatically done by str_to_num():

PHP Code:
#include <amxmodx>

public plugin_init()
{
    
register_srvcmd("numtest""cmdNumTest")
}


public 
cmdNumTest()
{
    new 
szArg[6], iArg
    read_argv
(1szArgcharsmax(szArg))
    
iArg str_to_num(szArg)
    
server_print("%s >> %i"szArgiArg)

Results:
Code:
numtest 5
5 >> 5
numtest 3.5
3.5 >> 3
numtest 4.2343
4.234 >> 4
__________________
fysiks is offline
Jhob94
AMX Mod X Donor
Join Date: Jul 2012
Old 08-14-2014 , 15:38   Re: check if number is float
Reply With Quote #2

Quote:
Originally Posted by fysiks View Post
You never need to check if it's a float, you simply need to truncate it which is automatically done by str_to_num():

PHP Code:
#include <amxmodx>

public plugin_init()
{
    
register_srvcmd("numtest""cmdNumTest")
}


public 
cmdNumTest()
{
    new 
szArg[6], iArg
    read_argv
(1szArgcharsmax(szArg))
    
iArg str_to_num(szArg)
    
server_print("%s >> %i"szArgiArg)

Results:
Code:
numtest 5
5 >> 5
numtest 3.5
3.5 >> 3
numtest 4.2343
4.234 >> 4
Finally someone that understands me
__________________
Jhob94 is offline
IAmReallyCool
Member
Join Date: Nov 2013
Old 08-14-2014 , 17:23   Re: check if number is float
Reply With Quote #3

Quote:
Originally Posted by fysiks View Post
You never need to check if it's a float, you simply need to truncate it which is automatically done by str_to_num():

PHP Code:
#include <amxmodx>

public plugin_init()
{
    
register_srvcmd("numtest""cmdNumTest")
}


public 
cmdNumTest()
{
    new 
szArg[6], iArg
    read_argv
(1szArgcharsmax(szArg))
    
iArg str_to_num(szArg)
    
server_print("%s >> %i"szArgiArg)

Results:
Code:
numtest 5
5 >> 5
numtest 3.5
3.5 >> 3
numtest 4.2343
4.234 >> 4
Thanks a lot, fysiks, I got answer for my question!
IAmReallyCool is offline
Reply



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