Raised This Month: $ Target: $400
 0% 

float to num


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
striker07
Veteran Member
Join Date: Mar 2012
Location: Solar System/Earth/Belgi
Old 05-19-2012 , 09:09   float to num
Reply With Quote #1

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?
striker07 is offline
Hyper Nova
BANNED
Join Date: May 2012
Old 05-19-2012 , 09:11   Re: float to num
Reply With Quote #2

http://forums.alliedmods.net/showpos...3&postcount=13
Hyper Nova is offline
<VeCo>
Veteran Member
Join Date: Jul 2009
Location: Bulgaria
Old 05-19-2012 , 09:13   Re: float to num
Reply With Quote #3

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.
__________________
<VeCo> is offline
striker07
Veteran Member
Join Date: Mar 2012
Location: Solar System/Earth/Belgi
Old 05-19-2012 , 09:35   Re: float to num
Reply With Quote #4

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 ?
striker07 is offline
<VeCo>
Veteran Member
Join Date: Jul 2009
Location: Bulgaria
Old 05-19-2012 , 09:40   Re: float to num
Reply With Quote #5

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)
__________________
<VeCo> is offline
striker07
Veteran Member
Join Date: Mar 2012
Location: Solar System/Earth/Belgi
Old 05-19-2012 , 09:56   Re: float to num
Reply With Quote #6

ok thx, i also just tested it out.
works perfect
striker07 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 00:30.


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