problem with float
#1

HouseCost[InHouse[playerid]] is 35
that:
Код:
format(str,128,"%d",HouseCost[InHouse[playerid]]/2);
printing 17
and that
Код:
format(str,128,"%f",HouseCost[InHouse[playerid]]/2);
printing 0.00000

what is the problem here?
Reply
#2

35/2 = 17.5

- https://sampwiki.blast.hk/wiki/Format
Reply
#3

Quote:
Originally Posted by Cameltoe
I know
but with %d it prints 17 and with %f it prints 0.00000
Reply
#4

Try:
pawn Код:
format(str, 128, "%0.2f", Float:HouseCost[InHouse[playerid]] / Float:2);
Reply
#5

guys, stop leading him the rong way. if it prints 0.000000 thats the full float ammount. to shorten it to normal stature, put %.0f
Reply
#6

im guesing HouseCost[InHouse[playerid]] is a intger not a float and in this lies the problem
try
Код:
new Float:hc = HouseCost[InHouse[playerid]];
format(str, 128, "%.0f", hc / 2);
Reply
#7

Quote:
Originally Posted by (SF)Noobanatior
im guesing HouseCost[InHouse[playerid]] is a intger not a float and in this lies the problem
try
Код:
new Float:hc = HouseCost[InHouse[playerid]];
format(str, 128, "%.0f", hc / 2);
thanks thats working!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)