SA-MP Forums Archive
Math problem - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Math problem (/showthread.php?tid=489168)



Math problem - Redirect Left - 21.01.2014

I'm having a problem with some math, basically the below outputs '0.0000000' even though its not. (****** and my calculator confirm)

new speed = GetVSpeed(playerid);
new Float:newdist = speed / 3600;

Now, lets say that speed is 60. The output, according to ****** and my calculator should be '0.01666666666', however the output is actually given as 0.000000 when printed in string.

Any ideas whats going on with this? I assume its probably something very simple i'm overlooking.


Re: Math problem - SickAttack - 21.01.2014

Are you printing the float with %f? if not try it.


Re: Math problem - ProjectMan - 21.01.2014

pawn Код:
new Float:speed = GetVSpeed(playerid); //Float
new Float:newdist = speed / 3600;



Re: Math problem - Ballu Miaa - 21.01.2014

Quote:
Originally Posted by ProjectMan
Посмотреть сообщение
pawn Код:
new Float:speed = GetVSpeed(playerid); //Float
new Float:newdist = speed / 3600.0;
There you go. You defined speed as an integer first which you were dividing by a float which is not possible. Either you need to use cast functions to change int into float or you can simply make speed var as a float. Just like this poster quoted. Problem solved!

EDIT:

Quote:
Originally Posted by PowerPC603
Посмотреть сообщение
pawn Код:
new Float:speed = GetVSpeed(playerid); //Float
new Float:newdist = speed / 3600.0;
Also put 3600.0 as float.
To prevent warnings about tag mismatches and to be certain you're dividing a float by a float.
Yeah ofcourse my bad. Thanks to PPC for the help.


Re: Math problem - PowerPC603 - 21.01.2014

pawn Код:
new Float:speed = GetVSpeed(playerid); //Float
new Float:newdist = speed / 3600.0;
Also put 3600.0 as float.
To prevent warnings about tag mismatches and to be certain you're dividing a float by a float.


Re: Math problem - Redirect Left - 21.01.2014

Speed isn't a float (it's returned as a round value) so i didn't think i'd need to define it as a float?

edit: that did fix it, so thanks