Raised This Month: $12 Target: $400
 3% 

Value float or Integer?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Larcyn
Senior Member
Join Date: Oct 2010
Old 05-11-2012 , 17:10   Value float or Integer?
Reply With Quote #1

Hello,

How can I check if a value is a float or if it's an integer?

I need something similar like the PHP Function: is_float($x) and is_int($x)
http://php.net/manual/en/function.is-float.php
http://php.net/manual/en/function.is-int.php

Thanks in advance
__________________

Taking private requests, PM me for information.
Selling HideNSeek & Jailbreak plugins.

Selling Achievement API System (PHP &
MySQL / nVault)

Last edited by Larcyn; 05-11-2012 at 17:10.
Larcyn is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 05-11-2012 , 17:15   Re: Value float or Integer?
Reply With Quote #2

Give a context/code where you need that.
__________________
Arkshine is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 05-11-2012 , 17:25   Re: Value float or Integer?
Reply With Quote #3

Situation #1:
Code:
someFunction(any:value) {     // Do something with value }
Code:
// Call with an integer someFunction(1337); // Call with a float someFunction(13.37);

In this case, you would need to add another parameter to specify if the provided value is float or integer.

Situation #2:
Trying to determine if a string is a float or integer.

Code:
stock bool:is_str_float(const string[], bool:require_decimal=true) {     new count, pos, ch;     while((ch = string[pos++])) {         if(ch == '.') {             if(++count > 1) {                 return false;             }         }         else if(!('0' <= ch <= '9')) {             return false;         }     }     return (!require_decimal || count == 1); }
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!

Last edited by Exolent[jNr]; 05-12-2012 at 13:58.
Exolent[jNr] is offline
Larcyn
Senior Member
Join Date: Oct 2010
Old 05-12-2012 , 06:19   Re: Value float or Integer?
Reply With Quote #4

Thanks for your replys, but these can't help me. I should provide more information I guess.

I'm trying to add it into a calculator I made, http://forums.alliedmods.net/showthread.php?t=172415

PHP Code:
format(szArgcharsmax(szArg), "%d"mathEvaluateEquation(szArg)) 
I want to check if the output of mathEvaluateEquation(szArg) is an integer value or if it's a float so I can print out the correct value when a player is dividing something which will contain decimals.
__________________

Taking private requests, PM me for information.
Selling HideNSeek & Jailbreak plugins.

Selling Achievement API System (PHP &
MySQL / nVault)

Last edited by Larcyn; 05-12-2012 at 06:20.
Larcyn is offline
Xalus
Veteran Member
Join Date: Dec 2009
Location: Belgium
Old 05-12-2012 , 07:27   Re: Value float or Integer?
Reply With Quote #5

In CS it could be something like:

PHP Code:
new Float:Amount 5.2
if( Amount == float(floatround(Amount)) ) 
floatround will make Amount to 5, float makes it back to 5.0
so: 5.2 != 5.0

Means its a float
__________________
Retired.
Xalus is offline
claudiuhks
Yam Inside®™℠
Join Date: Jan 2010
Location: Living Randomly
Old 05-12-2012 , 07:39   Re: Value float or Integer?
Reply With Quote #6

You forgot an ), Exolent
__________________

Last edited by claudiuhks; 05-12-2012 at 07:40.
claudiuhks is offline
Send a message via MSN to claudiuhks Send a message via Yahoo to claudiuhks Send a message via Skype™ to claudiuhks
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 05-12-2012 , 12:59   Re: Value float or Integer?
Reply With Quote #7

Quote:
Originally Posted by Larcyn View Post
Thanks for your replys, but these can't help me. I should provide more information I guess.

I'm trying to add it into a calculator I made, http://forums.alliedmods.net/showthread.php?t=172415

PHP Code:
format(szArgcharsmax(szArg), "%d"mathEvaluateEquation(szArg)) 
I want to check if the output of mathEvaluateEquation(szArg) is an integer value or if it's a float so I can print out the correct value when a player is dividing something which will contain decimals.
A function like that should always return a float and therefore you can always use something like "%.2f". You should post that entire mathEvaluateEquation() function if you want more accurate help.
__________________
fysiks is offline
Larcyn
Senior Member
Join Date: Oct 2010
Old 05-12-2012 , 16:16   Re: Value float or Integer?
Reply With Quote #8

Quote:
Originally Posted by fysiks View Post
A function like that should always return a float and therefore you can always use something like "%.2f". You should post that entire mathEvaluateEquation() function if you want more accurate help.
I am aware that I can use %.2f in this case, but it would be better if i just had plain numbers instead of decimals when it's an integer value.
__________________

Taking private requests, PM me for information.
Selling HideNSeek & Jailbreak plugins.

Selling Achievement API System (PHP &
MySQL / nVault)
Larcyn is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 05-13-2012 , 02:20   Re: Value float or Integer?
Reply With Quote #9

Quote:
Originally Posted by Larcyn View Post
I am aware that I can use %.2f in this case, but it would be better if i just had plain numbers instead of decimals when it's an integer value.
Did you try Xalus' method?
__________________
fysiks 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 15:32.


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