Floats
#1

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

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

pawn Код:
printf("%0.1f", vhealth);
0.1 means 1 decimal place.

edit: Farsek beat me.
Reply
#4

Great that works! Thanks Farsek and Donya
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)