[HELP] How to get one digit from integer
#1

pawn Код:
// example
new level = GetPlayerDrunkLevel(playerid);
printf("You have %d promilles", level);
How to get just one digit from 'level' variable... Example, if level value is 1000 i wanna to print just 1 i tryed with something like this, but that dosen't work...

pawn Код:
new level = GetPlayerDrunkLevel(playerid);
printf("You have %1.1f promilles", float(level));
Reply
#2

bah, just divide it by 1000:
pawn Код:
printf("You have %d promilles", level/1000);
at levels >=10000, it will indeed print 2 digits.
Reply
#3

Lol, good idea, thanks.
Reply
#4

pawn Код:
new level = GetPlayerDrunkLevel(playerid);
new level2[ 9 ];
valstr(level2,level);
new lenght = strlen(level2);
strdel(level2, 1, lenght);
level = strval(level2);
printf("You have %d promilles", level);
Reply
#5

that's what I meant to do but I'm wondering if there is a shorter way to do it, Babul way is just okey

Thanks anyway...
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)