SA-MP Forums Archive
Not Working Function - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Not Working Function (/showthread.php?tid=169332)



Not Working Function - Kyle - 19.08.2010

pawn Код:
stock randfloat(number)
{
    new number2,string[156],string2[156];
    number = random(number);
    number2 = random(9);
    format(string,sizeof(string),"%d.%d",number,number2);
    new Float:var = floatstr(string);

    format(string2,sizeof(string2),"%0.1f",var);
    new Float:var2 = floatstr(string2);

    return _: var2;
}
What is Up with that code, it dont return any errors but it dont function correctly.

It always has like 7859185524.0

But notice it always has .0 at the end of the number.

Regards


Re: Not Working Function - [HUN]Jaki - 19.08.2010

pawn Код:
randfloat(max){
  new tmp = random(max*1000); //1000 gives back %.3f, 100 gives back %.2f and so on
  new result = floatdiv(float(tmp), 1000.0);
  return result;
}
I think this should work, but I didn't test it.


Re: Not Working Function - Kyle - 19.08.2010

Doesnt work.


Re: Not Working Function - [HUN]Jaki - 19.08.2010

Do you have any errors/warnings?
Or it simply returns something wrong?


Re: Not Working Function - Kyle - 19.08.2010

It returns numbers like

1129689578.0

Ive noticed the number always starts with 11


Re: Not Working Function - [HUN]Jaki - 19.08.2010

I forgot the "Float:"-s.
pawn Код:
Float:randfloat(max){
  new tmp = random(max*1000); //1000 gives back %.3f, 100 gives back %.2f and so on
  new Float:result = floatdiv(float(tmp), 1000.0);
  return Float:result;
}
Tested.