Here's a new version with a few string handling functions changed around to use the ones that deal with bytes rather than cells (which are 4 bytes each).
PHP Code:
stock AddCommas( iNum, String:szOutput[] , iLen )
{
new String:szTmp[ 15 ] , iOutputPos , iNumPos , iNumLen;
if ( iNum < 0 )
{
szOutput[ iOutputPos++ ] = '-';
iNum = ~iNum + 1; // Two's complement conversion
}
IntToString( iNum, szTmp, sizeof(szTmp));
iNumLen = strlen(szTmp);
if ( iNumLen <= 3 )
{
iOutputPos += StrCat( szOutput , iLen , szTmp );
}
else
{
while ( ( iNumPos < iNumLen ) && ( iOutputPos < iLen ) )
{
szOutput[ iOutputPos++ ] = szTmp[ iNumPos++ ];
if ( ( iNumLen - iNumPos ) && !( (iNumLen = iNumPos ) % 3 ) )
{
szOutput[ iOutputPos++ ] = ',';
}
}
szOutput[ iOutputPos ] = '\0';
}
return iOutputPos;
}
__________________