Raised This Month: $32 Target: $400
 8% 

Solved Floatround to next integer


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Depresie
Veteran Member
Join Date: Nov 2013
Old 09-02-2017 , 07:39   Floatround to next integer
Reply With Quote #1

Any one knows how i could transform a float to an integer but to always be rounded like

Code:
12.1 -> 13
instead of
Code:
12.1 -> 12
__________________

Last edited by Depresie; 09-19-2017 at 17:40.
Depresie is offline
PRoSToTeM@
Veteran Member
Join Date: Jan 2010
Location: Russia, Ivanovo
Old 09-02-2017 , 07:45   Re: Floatround to next integer
Reply With Quote #2

floatround_ceil, but for negative numbers:
Code:
-12.1 -> -12
__________________
PRoSToTeM@ is offline
Send a message via ICQ to PRoSToTeM@ Send a message via Skype™ to PRoSToTeM@
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 09-02-2017 , 09:25   Re: Floatround to next integer
Reply With Quote #3

PHP Code:
/* Different methods of rounding */
enum floatround_method {
    
floatround_round 0,
    
floatround_floor,
    
floatround_ceil,
    
floatround_tozero
}; 
PHP Code:
new Float:fVal 12.1;
    
server_print"%f = %d" fVal floatroundfVal floatround_ceil ) ); 
Output:
Code:
12.100000 = 13
__________________
Bugsy is offline
Depresie
Veteran Member
Join Date: Nov 2013
Old 09-19-2017 , 07:47   Re: Floatround to next integer
Reply With Quote #4

Any idea what is the outcome of the division of two integers that normally would result into a value with decimals ?

PHP Code:

new int1 3
new int2 2

int1 
int2 = ? 
int2 int1 = ? 
__________________

Last edited by Depresie; 09-19-2017 at 07:47.
Depresie is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 09-19-2017 , 07:54   Re: Floatround to next integer
Reply With Quote #5

My guess is 1 and 0 respectively. Try and let us know.
__________________
Bugsy is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 09-19-2017 , 09:36   Re: Floatround to next integer
Reply With Quote #6

Lookup "integer division".
__________________
fysiks is offline
KiLLeR.
Senior Member
Join Date: Jul 2014
Location: Bulgaria
Old 09-19-2017 , 17:39   Re: Floatround to next integer
Reply With Quote #7

As fysiks said that's called integer division and result is the number without everything after the decimal point.

3 / 2 = 1.5 (remove .5 and you will receive 1)
2 / 3 = 0.(6) (remove .(6) and you will receive 0)

Last edited by KiLLeR.; 09-19-2017 at 17:42.
KiLLeR. 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 19:05.


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