Raised This Month: $ Target: $400
 0% 

return float


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
whosyourdaddy
Senior Member
Join Date: Apr 2008
Old 01-02-2010 , 05:06   return float
Reply With Quote #1

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?
whosyourdaddy is offline
wyrda
Member
Join Date: Nov 2009
Old 01-02-2010 , 05:42   Re: return float
Reply With Quote #2

your method should be like this
public Float:test()
{
//your code
}
__________________
wyrda is offline
whosyourdaddy
Senior Member
Join Date: Apr 2008
Old 01-02-2010 , 05:47   Re: return float
Reply With Quote #3

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

Last edited by whosyourdaddy; 01-02-2010 at 06:06.
whosyourdaddy is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 01-02-2010 , 07:34   Re: return float
Reply With Quote #4

You can using structures :

Code:
enum Data {      myVar,      Float:myVar2 }; new NewRanks[33][Data]
__________________
Arkshine is offline
whosyourdaddy
Senior Member
Join Date: Apr 2008
Old 01-02-2010 , 13:27   Re: return float
Reply With Quote #5

how do i make a float only have 2 decimal places for example instead ofi t being 10.00000 it will be 10.00
whosyourdaddy is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 01-02-2010 , 13:30   Re: return float
Reply With Quote #6

If you want to display only 2 numbers, use %.2f
__________________
Arkshine is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 01-02-2010 , 14:17   Re: return float
Reply With Quote #7

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 
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!

Last edited by Exolent[jNr]; 01-02-2010 at 21:42.
Exolent[jNr] is offline
whosyourdaddy
Senior Member
Join Date: Apr 2008
Old 01-02-2010 , 16:06   Re: return float
Reply With Quote #8

exactly what i need but i got an error on this line with tag mismatch

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


whosyourdaddy is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 01-02-2010 , 16:08   Re: return float
Reply With Quote #9

Just to know, the whole plugin needs to work with 2 decimals ?
__________________
Arkshine is offline
whosyourdaddy
Senior Member
Join Date: Apr 2008
Old 01-02-2010 , 16:18   Re: return float
Reply With Quote #10

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
whosyourdaddy 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 04:10.


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