SA-MP Forums Archive
[HELP]Number in variable with comma - 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: [HELP]Number in variable with comma (/showthread.php?tid=440313)



[HELP]Number in variable with comma - x-file - 29.05.2013

Hello.
I need to make one script but i stoped to div.
For example I have two numbers 11 and 2. I want to div it. (11/2)
simple new num=11/2 i get just 5
new float:num=11/2 i get 55
but how to get 5.5?


Re: [HELP]Number in variable with comma - Pottus - 29.05.2013

Your dividing integers but your result would be a float so you need to do some conversions.

the float() function takes an integer and converts it to a float.

The solution is quite simple.

new Float:result;
result = floatdiv(float(11), float(5));


Re: [HELP]Number in variable with comma - x-file - 29.05.2013

new Float:Number1 = 100, Float:Number2 = 95;
new Float:test;
test = floatdiv(Number1, Number2);
format(msg,sizeof(msg),"I get: %i",test);
SendClientMessage(playerid,RED,msg);

I made it but test now is: 1065794722. And I dont get it why


Re: [HELP]Number in variable with comma - Pottus - 29.05.2013

format(msg,sizeof(msg),"I get: %i",test);

gotta use the Float specifier

format(msg,sizeof(msg),"I get: %f",test);


Re: [HELP]Number in variable with comma - x-file - 29.05.2013

Nice, Thank you