AlliedModders

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

ng1200 10-26-2007 14:49

Floats Help
 
Code:
    new Float:Ratio = float(g_CarMaxSpeed[id] / 1000)     g_Userspeed[id] = Ratio * g_PredefGears[g_CurrentGear[id]]     server_print("%f %f", Ratio, g_Userspeed[id])

Prints 0.0000000 0.00000000

Few notes:
g_CarMaxSpeed[id] is 485
g_PredefGears[g_CurrentGear[id]] is 1

What is the proper way to do this?

Thanks in advance, DF3.

Alka 10-26-2007 14:56

Re: Floats Help
 
Code:

new Float:Ratio = float(g_CarMaxSpeed[id]) / 1000.0;
g_Userspeed[id] = Ratio * float(g_PredefGears[g_CurrentGear[id]]);
server_print("%.1f | %.1f", Radio, g_Userspeed[id]);



Note: g_Userspeed[id] must be a float too :s

ng1200 10-26-2007 15:42

Re: Floats Help
 
Quote:

Originally Posted by Alka (Post 546421)
Code:

new Float:Ratio = float(g_CarMaxSpeed[id]) / 1000.0;
g_Userspeed[id] = Ratio * float(g_PredefGears[g_CurrentGear[id]]);
server_print("%.1f | %.1f", Radio, g_Userspeed[id]);



Note: g_Userspeed[id] must be a float too :s

g_Userspeed is already a float :)
Thanks for the help.

kp_uparrow 10-27-2007 01:07

Re: Floats Help
 
whats the %.1f for?

Alka 10-27-2007 01:33

Re: Floats Help
 
Quote:

Originally Posted by kp_uparrow (Post 546600)
whats the %.1f for?

Show's only 1 digit after . E.g 128.9

kp_uparrow 10-27-2007 03:06

Re: Floats Help
 
wow why was that not written in the scripting wiki s, been looking for that for ages

RaYden 10-27-2007 11:39

Re: Floats Help
 
lol

Greenberet 10-27-2007 12:04

Re: Floats Help
 
Quote:

Originally Posted by kp_uparrow (Post 546613)
wow why was that not written in the scripting wiki s, been looking for that for ages

well it is...
http://www.amxmodx.org/funcwiki.php?go=func&id=49 points you to the c++ printf http://www.cplusplus.com/reference/c...io/printf.html and it is explained there.


All times are GMT -4. The time now is 01:20.

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