Possible to get the first char of an integer? - 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)
+--- Thread: Possible to get the first char of an integer? (
/showthread.php?tid=491161)
Possible to get the first char of an integer? -
Hoborific - 29.01.2014
Was wondering how I would go about this in PAWN.
Re: Possible to get the first char of an integer? -
Konstantinos - 29.01.2014
pawn Код:
stock GetFirstNumber(number)
{
new
number_str[12],
bool: negative;
valstr(number_str, number);
if (number < 0) negative = true;
return (negative) ? (number_str[1]) : (number_str[0]);
}
Test:
pawn Код:
printf("%c", GetFirstNumber(654321));
printf("%c", GetFirstNumber(-54321));
and outputs:
This is what you want, if I understood correct.
Re: Possible to get the first char of an integer? -
Hoborific - 29.01.2014
Yes it was, thank you.