Print %f remains 0
#1

Hi,

I'm trying to make a simple ranking script. My ranks are working already but I also want to have a exp bar. i managed to create an expbar that changes size with the amount of kills left. however i want to display the percentage, somehow it remains 0 after the calculation

Код:
        killsleft[playerid] = tillnext[playerid] - GetPlayerScore(playerid);
	units[playerid] = (638/ tillnext[playerid]) * killsleft[playerid];
	displaypercentage[playerid] = (units[playerid]/638)*100;//this line goes wrong
	
	new string[24+3+1];
	format(string,sizeof(string),"Exp: %f%%", displaypercentage[playerid]);
Ok, so 638 is the maximum width, units[playerid] is the width of the bar(this changes when the player makes more kills)
Reply
#2

Attempt this:

pawn Код:
// change
new displaypercentage[MAX_PLAYERS];
// to
new Float:displaypercentage[MAX_PLAYERS];
// Also, do this:

format(string,sizeof(string),"Exp: %f", displaypercentage[playerid]);
Reply
#3

I tried it but it doesn't have any effect except for that the percentage sign after the "Exp: 0.000000" is removed. Good suggestion though. It seems that somehow the deviding makes it 0
Reply
#4

Im not sure about this

as you are using percentage i think you must use
Example
pawn Код:
format(string,sizeof(string),"Exp: %02f", displaypercentage[playerid]);
as you insert a Floating number
Reply
#5

Thats not it either, i tested it. it now shows "Exp: 00.00000" in the textdraw
Reply
#6

What are the tags of all those variables? An integer divided by another integer will remain an integer. There is no implied conversion.
Reply
#7

that could be the problem, is there a way to cast to a different datatype like in java?

EDIT: NVM it did the trick, thanks. i changed both the datatypes to float
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)