Raised This Month: $ Target: $400
 0% 

Formatting float


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
redivcram
Veteran Member
Join Date: Jul 2014
Location: Serbia
Old 12-24-2015 , 15:41   Formatting float
Reply With Quote #1

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?

Last edited by Arkshine; 12-25-2015 at 03:45.
redivcram is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 12-24-2015 , 15:49   Re: Formatting float
Reply With Quote #2

To convert a float to int use floatround.
__________________

Last edited by HamletEagle; 12-24-2015 at 15:49.
HamletEagle is offline
redivcram
Veteran Member
Join Date: Jul 2014
Location: Serbia
Old 12-24-2015 , 15:55   Re: Formatting float
Reply With Quote #3

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.
redivcram is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 12-24-2015 , 16:00   Re: Formatting float
Reply With Quote #4

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)

Last edited by klippy; 12-24-2015 at 16:03.
klippy is offline
redivcram
Veteran Member
Join Date: Jul 2014
Location: Serbia
Old 12-24-2015 , 16:01   Re: Formatting float
Reply With Quote #5

Thanks
redivcram is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 12-25-2015 , 01:32   Re: Formatting float
Reply With Quote #6

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.
__________________
fysiks is offline
Reply


Thread Tools
Display Modes

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 17:52.


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