AlliedModders

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

striker07 05-19-2012 09:09

float to num
 
Hello,

how can I turn a float number to a normal number
example:
I wanna turn a float : 1.65853543
to a number : 1 or 2 doesnt matter how it rounds off.

I was thinking about using float_to_str and then str_to_num.

wil this give me the desired effect that i need?

Hyper Nova 05-19-2012 09:11

Re: float to num
 
http://forums.alliedmods.net/showpos...3&postcount=13

<VeCo> 05-19-2012 09:13

Re: float to num
 
float() converts int to float.
floatround() converts float to int.
num_to_str() converts int to string.
str_to_num() converts string to int.
float_to_str() converts float to string.
str_to_float() converts string to float.

striker07 05-19-2012 09:35

Re: float to num
 
so
PHP Code:

g_fFloat1 3.642148
g_iNum1 
floatround(g_fFloat1floatround_round); 

will round the float to integer 4?

or wil it just work away the comma so that g_iNum1 would be 3642148 ?

<VeCo> 05-19-2012 09:40

Re: float to num
 
It will return 4.

floatround_round rounds to nearest int. (3.642148 -> 4)
floatround_floor rounds to nearest smaller int. (3.642148 -> 3)
floatround_ceil rounds to nearest larger int. (3.642148 -> 4) (useful for 3.22 for example)
floatround_zero rounds to nearest to 0 int. (3.642148 -> 3) (useful for negative values)

striker07 05-19-2012 09:56

Re: float to num
 
ok thx, i also just tested it out.
works perfect :)


All times are GMT -4. The time now is 00:30.

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