AlliedModders

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

whosyourdaddy 01-02-2010 05:06

return float
 
pretty much i have a function like this and im gettin an error on it

Code:

public test()
{
    new Float:test = 0.0

    return test
}

am i allowed to return floats?

wyrda 01-02-2010 05:42

Re: return float
 
your method should be like this
public Float:test()
{
//your code
}

whosyourdaddy 01-02-2010 05:47

Re: return float
 
thanks that worked heres another question lets say i have NewRanks[33][2] and i want NewRanks[33][1] to be a float but NewRanks[33][0] to not be a float is it possible in doing that some how?

edited*****

nvm im just gonna use float() to make the integer to a float and then floatround() it when i want it into an integer again but thanks alot for ur help on the first post

Arkshine 01-02-2010 07:34

Re: return float
 
You can using structures :

Code:
enum Data {      myVar,      Float:myVar2 }; new NewRanks[33][Data]

whosyourdaddy 01-02-2010 13:27

Re: return float
 
how do i make a float only have 2 decimal places for example instead ofi t being 10.00000 it will be 10.00

Arkshine 01-02-2010 13:30

Re: return float
 
If you want to display only 2 numbers, use %.2f

Exolent[jNr] 01-02-2010 14:17

Re: return float
 
If you want to truncate decimal places in your code and not in printing, you can use this:
PHP Code:

stock Float:TruncateDecimalPlaces( const Float:fValue, const iDecimalPlaces )
{
    if( 
iDecimalPlaces )
    {
        return 
floatfloatroundfValuefloatround_floor ) );
    }
    
    static const 
MAXIMUM_DECIMAL_PLACES 6;
    
    new 
Float:fShifter floatpower10miniDecimalPlacesMAXIMUM_DECIMAL_PLACES ) ) );
    
    return 
floatroundfValue fShifterfloatround_floor ) / fShifter;


PHP Code:

new Float:fMyVariable TruncateDecimalPlaces123.456789);
// fMyVariable = 123.450000 


whosyourdaddy 01-02-2010 16:06

Re: return float
 
exactly what i need but i got an error on this line with tag mismatch

Code:

    return float( floatround( fValue * fShifter, floatround_floor ) / fShifter );




Arkshine 01-02-2010 16:08

Re: return float
 
Just to know, the whole plugin needs to work with 2 decimals ?

whosyourdaddy 01-02-2010 16:18

Re: return float
 
ya so 14.5555 will output 14.55 when its called cause im makin the plugin do calculations so its not like i can just .2f% it and all


All times are GMT -4. The time now is 04:10.

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