AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Functions (round,ceil,floor) IDK (https://forums.alliedmods.net/showthread.php?t=189941)

kulers2010 07-12-2012 17:56

Functions (round,ceil,floor) IDK
 
Can someone can tellRound,ceil,floor

Its like PHP
http://php.net/manual/en/function.ceil.php Example(5.5 to 6; 5,4 to 6)
http://php.net/manual/en/function.floor.php Example(5.5 to 5; 5,4 to 5)
http://php.net/manual/en/function.round.php Example(5.5 to 6; 5,4 to 5)

Exolent[jNr] 07-12-2012 17:59

Re: Functions (round,ceil,floor) IDK
 
ceil(x) = floatround(x, floatround_ceil)
floor(x) = floatround(x, floatroud_floor)
round(x) = floatround(x)

kulers2010 07-12-2012 18:04

Re: Functions (round,ceil,floor) IDK
 
Tnx,

new Skaits = floatround(Users/MAX_PER_CT,floatround_ceil);
Tag mismach

jimaway 07-12-2012 18:43

Re: Functions (round,ceil,floor) IDK
 
use floats, not ints

ConnorMcLeod 07-13-2012 00:37

Re: Functions (round,ceil,floor) IDK
 
new Skaits = Users / MAX_PER_CT

Page 103 : http://www.compuphase.com/pawn/Pawn_Language_Guide.pdf
Code:

        /          e1 / e2
                  Results  in  the  division of  e1 by  e2.  The  result  is  truncated
                  to the nearest integral value that is less than or equal to the
                  quotient.  Both negative and positive values are rounded down,
                  i.e. towards −∞.


For positive values, this should work :

PHP Code:

enum round_method {
    
round,
    
floor,
    
ceil
}

Divideround_method:method floor )
{
    if( !
)
    {
        
abort(AMX_ERR_DIVIDE"Trying to divide by 0")
        return 
// ?
    
}
    
    switch( 
method )
    {
        case 
floor:
        {
            return 
b
        
}
        case 
ceil:
        {
            return 
+ !!(b)
        }
        case 
round:
        {
            return 
+ !!( * (b) > )
        }
    }
    return 
0



Irena 07-13-2012 06:03

Re: Functions (round,ceil,floor) IDK
 
yeah round will round the value after point like it would do 5.4 to 5 and 5.6 to 6.CEIL function will give the Highest value of the given number where as FLOOR function will give the lowest value to the given Number. ceil will round 23.4 to 24 and floor will gave 23 even if its 23.8

devWaleed 07-20-2013 09:26

Re: Functions (round,ceil,floor) IDK
 
But why this give me a tag mismatch error?

PHP Code:

ePlayer        =    floatround((num num2)/2floatround_ceil); 

If I provide a float, it gives me no error but gives error with variables >.<

fysiks 07-20-2013 19:14

Re: Functions (round,ceil,floor) IDK
 
Quote:

Originally Posted by devWaleed (Post 1995016)
But why this give me a tag mismatch error?

PHP Code:

ePlayer        =    floatround((num num2)/2floatround_ceil); 

If I provide a float, it gives me no error but gives error with variables >.<

Show the whole code. num and num2 must be floating point variables and 2 should be 2.0


All times are GMT -4. The time now is 09:19.

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