Floats - 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)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Floats (
/showthread.php?tid=266783)
Floats -
BLAbla93 - 06.07.2011
Ok so I am trying to round the vehicle health to 100.0%, 95.3% and so forth so I did this
Код:
new Float:vhealth;
GetVehicleHealth(GetPlayerVehicleID(playerid), vhealth);
vhealth = floatdiv(vhealth, 1000.0);
vhealth = floatmul(vhealth, 1000);
vhealth = floatround(vhealth);
vhealth = floatdiv(vhealth, 10);
but that will return 100.000000000000%
or 99.30000000000%
and so forth is there anyway to chop off the extra 0's as I did not see a float function that would do it.
Re: Floats -
Farsek - 06.07.2011
if you want to use it in a string, try %.1f (65.6) .
I don't think the number of decimal places from a float can be limited in pawn ..
Re: Floats -
Donya - 06.07.2011
pawn Код:
printf("%0.1f", vhealth);
0.1 means 1 decimal place.
edit: Farsek beat me.
Re: Floats -
BLAbla93 - 06.07.2011
Great that works! Thanks Farsek and Donya