AlliedModders

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

freamer 02-28-2007 10:14

maths question
 
I would like to know how to multiply/divide floats
for example i have number 33 , i need to get 0.33
if i just write new float:var = 33 / 100.0
it gives me the tag missmatch error and wrong number
ive also tried floatmul and floatdiv but it didnt work

thank you for your help

SAMURAI16 02-28-2007 10:19

Re: maths question
 
an example:
PHP Code:

public function(id)
{
    new 
Float:var = 33 100.0
    
    client_print
(id,print_chat,"your health is %f",var)



freamer 02-28-2007 10:23

Re: maths question
 
Code:

public dividef(one, another)
{
    new Float:var = one / another
    return var
}

will this work fine?

SAMURAI16 02-28-2007 10:25

Re: maths question
 
no. will got problems with return (tag mismatch)

freamer 02-28-2007 10:27

Re: maths question
 
Quote:

Originally Posted by SAMURAI16 (Post 446655)
no. will got problems with return (tag mismatch)

what should i change then?

SAMURAI16 02-28-2007 10:28

Re: maths question
 
1)First read this : http://wiki.amxmodx.org/index.php/Pawn#Floats It's few lines
2) return another value

freamer 02-28-2007 10:57

Re: maths question
 
im really stuck now
Code:

public dividef(one)
{
    new Float:var = floatround(float(one) / 100.0)
    server_print("%f / %f / %f", float(one), 100.0, float(var))
    return float(var)
}

in console it has written 33.00000 / 100.00000 / 0.0000
why can this happen?

floatdiv gave the same result

:) removed floatround and all worked fine

P34nut 02-28-2007 12:31

Re: maths question
 
Code:
public Float:dividef(Float:fOne, Float:fAnother) {     new Float:var = fOne / fAnother     return var }

if it doesnt work

Code:
public Float:dividef(Float:fOne, Float:fAnother) {     new Float:var = floatdiv(fOne, fAnother)     return var }

[ --<-@ ] Black Rose 03-03-2007 07:31

Re: maths question
 
Why create vars?
Code:
public Float:dividef(Float:fOne, Float:fAnother)     return fOne / fAnother
equals
Code:
floatdiv(fOne, fAnother)
equals
Code:
fOne / fAnother
You don't even need a function for that.


All times are GMT -4. The time now is 00:37.

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