Not Working Function
#1

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

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

Doesnt work.
Reply
#4

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

It returns numbers like

1129689578.0

Ive noticed the number always starts with 11
Reply
#6

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


Forum Jump:


Users browsing this thread: 1 Guest(s)