SA-MP Forums Archive
Rounding numbers? - 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: Rounding numbers? (/showthread.php?tid=302588)



Rounding numbers? - sciman001 - 09.12.2011

How do I round a number to the nearest hundreth?


Re: Rounding numbers? - MadeMan - 09.12.2011

pawn Код:
number = floatround(number*100.0)/100.0;



Re: Rounding numbers? - sciman001 - 09.12.2011

Код:
dcmd_stats(playerid, params[])
{
	#pragma unused params
    new msg[128];
    
    new Float:kd = floatround(pInfo[playerid][kills] / pInfo[playerid][deaths]*100.0)/100.0;

	format(msg, sizeof(msg), "Kills: %i | Deaths: %i | Ratio: %f", pInfo[playerid][kills], pInfo[playerid][deaths], kd);

	SCM(playerid, COLOR_RED, "_________STATS_________");
	SCM(playerid, COLOR_RED, msg);
	return 1;
}
When kills is 635 and deaths is 86 it says this:
Код:
Kills: 635 | Deaths: 86 | Ratio: 7.000000
Any ideas?


Re: Rounding numbers? - MadeMan - 09.12.2011

Try this

pawn Код:
new Float:kd = floatround((pInfo[playerid][kills] / pInfo[playerid][deaths])*100.0)/100.0;



Re: Rounding numbers? - sciman001 - 09.12.2011

7.000000


Re: Rounding numbers? - sciman001 - 09.12.2011

Dude, its giving me 7.000000 with this:
Код:
new Float:kd = pInfo[playerid][kills] / pInfo[playerid][deaths];
WTH?


Re: Rounding numbers? - Wesley221 - 09.12.2011

pawn Код:
format(msg, sizeof(msg), "Kills: %i | Deaths: %i | Ratio: %0.2f", pInfo[playerid][kills], pInfo[playerid][deaths], kd);
Notice the '%0.2f'. Change the 2 to the decimals you want


Re: Rounding numbers? - sciman001 - 09.12.2011

That helps. But its still 7.00 when it should be 7.38 or so. Any ideas? I cant figure it out!


Re: Rounding numbers? - sciman001 - 09.12.2011

Sorry for double post, but if kills is 1 and deaths is 2 it says 0.00... any ideas? Thanks for all the help so far. Hope I get it to work...


Re: Rounding numbers? - MadeMan - 09.12.2011

pawn Код:
new Float:kd = floatdiv(pInfo[playerid][kills], pInfo[playerid][deaths]);