Rounding numbers?
#1

How do I round a number to the nearest hundreth?
Reply
#2

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

Код:
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?
Reply
#4

Try this

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

7.000000
Reply
#6

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

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

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

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

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


Forum Jump:


Users browsing this thread: 2 Guest(s)