SA-MP Forums Archive
Quick issue - 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: Quick issue (/showthread.php?tid=582757)



Quick issue - ZachKnoxx - 23.07.2015

I've been playing around with the code a bit and haven't been able to find a good way to remove the extra decimals. I was wondering if there was a way you could do it so it could only show two decimals. For example, "Health: 49.00" instead of "Health: 49.000000"



Код HTML:
  	format(string, sizeof(string), "Health: %f, Armour: %f", PlayerInfo[playerid][pHealth], PlayerInfo[playerid][pArmour]);
	SendClientMessage(playerid, COLOR_WHITE, string);



Re: Quick issue - SickAttack - 23.07.2015

pawn Код:
format(string, sizeof(string), "Health: %.2f, Armour: %.2f", PlayerInfo[playerid][pHealth], PlayerInfo[playerid][pArmour]);
SendClientMessage(playerid, COLOR_WHITE, string);



Re: Quick issue - xVIP3Rx - 23.07.2015

As SickAttack said, I would like to add that if you change the "x" in "%0.xf" it declares the number of decimals the float has,

also, if you want to turn it into an integer (no decimals), use floatround
pawn Код:
floatround(health, floatround_round); //This returns an integer, so make sure your replacing "%f" with "%d" while formatting