Math problem
#1

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.
Reply
#2

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

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

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.
Reply
#5

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.
Reply
#6

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)