AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Formatting float (https://forums.alliedmods.net/showthread.php?t=276623)

redivcram 12-24-2015 15:41

Formatting float
 
How do I make make a float display as an integer? For example I have
PHP Code:

new Float:var = 5.0 

Now how do I format it so It would display as 5?

HamletEagle 12-24-2015 15:49

Re: Formatting float
 
To convert a float to int use floatround.

redivcram 12-24-2015 15:55

Re: Formatting float
 
Like this?
PHP Code:

new Float:gVar 10.0

public function(id)
{
         
floatround(Float:gVar)
         
client_print(idprint_chat"Huehuehue : %d"gVar)


Just searched it
First time hearing about floatround, and what are the differences between methods? 2nd parameter of floatround.

klippy 12-24-2015 16:00

Re: Formatting float
 
Code:

client_print(id, print_chat, "My var: %i", floatround(gVar));
It returns the integer representation of a float value.
And modes are:
Code:

enum floatround_method {
    floatround_round = 0,
    floatround_floor,
    floatround_ceil,
    floatround_tozero
};

round is just classic rounding (to the nearest int). ( 17.6 -> 18 )
floor rounds downwards ( 17.8 -> 17 )
ceil rounds upwards ( 17.3 -> 18 )
tozero rounds toward zero ( -17.7 -> -17 | 17.7 -> 17)

redivcram 12-24-2015 16:01

Re: Formatting float
 
Thanks

fysiks 12-25-2015 01:32

Re: Formatting float
 
Don't remove your posts. If it's solved, just leave the original question so people know what the question was.

Quote:

Originally Posted by Rules
Do not blank out posts - if you solve your problem post the solution for others to find.



All times are GMT -4. The time now is 17:52.

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