If your numbers will always be within the signed int32 range ( -2,147,483,648 to 2,147,483,647 ) you can use the below. If the numbers can be outside of this range then this will take a bit more work.
Edit: Discovered -2,147,483,648 is not possible since the positive variant of this is number is 2,147,483,648 which is larger than 2,147,483,647. abs() is used in this function which fails. I have edited the below accordingly.
Result
Code:
-2147483647 = -2,147,483,647
2147483647 = 2,147,483,647
Code from my post in the thread posted above:
PHP Code:
#include <amxmodx>
new iMin = -2147483647;
new iMax = 2147483647;
public plugin_init()
{
new szNum[ 15 ];
AddCommas( iMin , szNum , charsmax( szNum ) );
server_print( "%d = %s" , iMin , szNum );
AddCommas( iMax , szNum , charsmax( szNum ) );
server_print( "%d = %s" , iMax , szNum );
}
public AddCommas( iNum , szOutput[] , iLen )
{
new szTmp[ 15 ] , iOutputPos , iNumPos , iNumLen;
if ( iNum < 0 )
{
szOutput[ iOutputPos++ ] = '-';
iNum = abs( iNum );
}
iNumLen = num_to_str( iNum , szTmp , charsmax( szTmp ) );
if ( iNumLen <= 3 )
{
iOutputPos += copy( szOutput[ iOutputPos ] , iLen , szTmp );
}
else
{
while ( ( iNumPos < iNumLen ) && ( iOutputPos < iLen ) )
{
szOutput[ iOutputPos++ ] = szTmp[ iNumPos++ ];
if( ( iNumLen - iNumPos ) && !( ( iNumLen - iNumPos ) % 3 ) )
szOutput[ iOutputPos++ ] = ',';
}
szOutput[ iOutputPos ] = EOS;
}
return iOutputPos;
}
__________________